package com.zdkj.subway.rca.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zdkj.common.security.service.PigxUser;
import com.zdkj.common.security.util.SecurityUtils;
import com.zdkj.subway.rca.dto.out.SwCkClearEmergencyReturnticketDTO;
import com.zdkj.subway.rca.entity.SwCkClearEmergencyReturnticket;
import com.zdkj.subway.rca.enums.SwCkClearRuleConstans;
import com.zdkj.subway.rca.mapper.SwCkClearEmergencyReturnticketMapper;
import com.zdkj.subway.rca.service.SwCkClearEmergencyReturnticketService;
import com.zdkj.subway.rca.service.SwCkClearRulesService;
import com.zdkj.subway.rca.util.LocalDateConverter;
import com.zdkj.subway.rca.util.LocalDateTimeConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 应急纸票和退换票清分操作
 * @Author lu
 * @Date 2021-08-17
 */
@Service
public class SwCkClearEmergencyReturnticketServiceImpl extends ServiceImpl<SwCkClearEmergencyReturnticketMapper,SwCkClearEmergencyReturnticket> implements SwCkClearEmergencyReturnticketService{
	 
	private static final Logger LOGGER = LoggerFactory.getLogger(SwCkClearEmergencyReturnticketServiceImpl.class);
	@Autowired
	 private SwCkClearRulesService swCkClearRuleService;


    @Override
    public List<SwCkClearEmergencyReturnticketDTO> listSwCkClearEmergencyReturnticket(String startDate, String endDate, String lineCode, String operatorsName) {
        List<SwCkClearEmergencyReturnticketDTO> list = this.baseMapper.listSwCkClearEmergencyReturnticket(startDate,endDate,operatorsName,lineCode);
        List<SwCkClearEmergencyReturnticketDTO> listNew = new ArrayList<>();

        String operators = null;
        for(SwCkClearEmergencyReturnticketDTO obj : list){
            if(!obj.getOperators().equals(operators) && operators != null){
                //计算相同运营商的合计
                SwCkClearEmergencyReturnticketDTO sum = getSum(operators, list);
                listNew.add(sum);
            }
            operators = obj.getOperators();
            listNew.add(obj);
        }
        if(list.size() > 0) { //最后一个运营商
            SwCkClearEmergencyReturnticketDTO sum = getSum(operators, list);
            listNew.add(sum);
        }
        SwCkClearEmergencyReturnticketDTO sumAll = getSum("合计", list);
        sumAll.setLineCode("--");
        sumAll.setLineName("--");
        listNew.add(sumAll);
        return listNew;
    }

    private SwCkClearEmergencyReturnticketDTO getSum(String operators, List<SwCkClearEmergencyReturnticketDTO> list){
        SwCkClearEmergencyReturnticketDTO sumSwCkClearEmergencyReturnticket = new SwCkClearEmergencyReturnticketDTO();
        sumSwCkClearEmergencyReturnticket.setOperators(operators);
        if(!operators.equals("合计")){
            sumSwCkClearEmergencyReturnticket.setLineCode("小计");
            sumSwCkClearEmergencyReturnticket.setLineName("小计");
        }
        if(operators.equals("合计")){
            sumSwCkClearEmergencyReturnticket.setOperatorsName(operators);
        }
        BigDecimal emeRecycle = new BigDecimal("0");
        BigDecimal emeSale = new BigDecimal("0");
        BigDecimal emeClear = new BigDecimal("0");
        BigDecimal streamXadtXadtSale = new BigDecimal("0");
        BigDecimal streamXadtXadtRecycle = new BigDecimal("0");
        BigDecimal streamXadtXadtClear = new BigDecimal("0");
        BigDecimal streamXadtAirRecycle = new BigDecimal("0");
        BigDecimal streamXadtAirClear = new BigDecimal("0");
        BigDecimal streamXadtXaztRecycle = new BigDecimal("0");
        BigDecimal streamXadtXaztClear = new BigDecimal("0");
        BigDecimal streamAirXadtSale = new BigDecimal("0");
        BigDecimal streamAirXadtRecycle = new BigDecimal("0");
        BigDecimal streamAirXadtClear = new BigDecimal("0");
        BigDecimal streamAirXixianRecycle = new BigDecimal("0");
        BigDecimal streamAirXixianClear = new BigDecimal("0");
        BigDecimal streamXaztXadtSale = new BigDecimal("0");
        BigDecimal streamXaztXadtRecycle = new BigDecimal("0");
        BigDecimal streamXaztXadtClear = new BigDecimal("0");
        BigDecimal streamXaztXixianRecycle = new BigDecimal("0");
        BigDecimal streamXaztXixianClear = new BigDecimal("0");
        BigDecimal failNormalAirStationSale = new BigDecimal("0");
        BigDecimal failNormalAirStationClear = new BigDecimal("0");
        BigDecimal failNormalAirOtherstationSale = new BigDecimal("0");
        BigDecimal failNormalAirOtherstationClear = new BigDecimal("0");
        BigDecimal failNormalAirTotalClear = new BigDecimal("0");
        BigDecimal failNormalXaztStationSale = new BigDecimal("0");
        BigDecimal failNormalXaztStationClear = new BigDecimal("0");
        BigDecimal failNormalXaztOtherstationSale = new BigDecimal("0");
        BigDecimal failNormalXaztOtherstationClear = new BigDecimal("0");
        BigDecimal failNormalXaztTotalClear = new BigDecimal("0");
        BigDecimal failSpeXadterrorSale = new BigDecimal("0");
        BigDecimal failSpeXadterrorSaleNine = new BigDecimal("0");
		BigDecimal failSpeXadterrorSaleSum = new BigDecimal("0");
        BigDecimal failSpeXadterrorClear = new BigDecimal("0");
        BigDecimal failSpeXadterrorClearNine = new BigDecimal("0");
        BigDecimal failSpeXadterrorClearSum = new BigDecimal("0");
        BigDecimal failSpeAirerrorSale = new BigDecimal("0");
        BigDecimal failSpeAirerrorClear = new BigDecimal("0");
        BigDecimal failSpeXazterrorSale = new BigDecimal("0");
        BigDecimal failSpeXazterrorClear = new BigDecimal("0");
        BigDecimal totalClear = new BigDecimal("0");

        //用于退换票页面的应急纸票金额
        BigDecimal streamXadtSale = new BigDecimal("0");
        BigDecimal streamXadtRecycle = new BigDecimal("0");
        BigDecimal streamXadtClear = new BigDecimal("0");
        BigDecimal streamAirSale = new BigDecimal("0");
        BigDecimal streamAirRecycle = new BigDecimal("0");
        BigDecimal streamAirClear = new BigDecimal("0");
        BigDecimal streamXaztSale = new BigDecimal("0");
        BigDecimal streamXaztRecycle = new BigDecimal("0");
        BigDecimal streamXaztClear = new BigDecimal("0");

        //9号线、14号线合计清分金额
        BigDecimal streamXaztTotalClear = new BigDecimal("0");
        BigDecimal streamAirTotalClear = new BigDecimal("0");

        for(SwCkClearEmergencyReturnticketDTO obj : list){
            if(operators.equals("合计") || operators.equals(obj.getOperators())){
                emeRecycle = emeRecycle.add(getData2(obj.getEmeRecycle()));
                emeSale = emeSale.add(getData2(obj.getEmeSale()));
                emeClear = emeClear.add(getData2(obj.getEmeClear()));
                streamXadtXadtSale = streamXadtXadtSale.add(getData2(obj.getStreamXadtXadtSale()));
                streamXadtXadtRecycle = streamXadtXadtRecycle.add(getData2(obj.getStreamXadtXadtRecycle()));
                streamXadtXadtClear = streamXadtXadtClear.add(getData2(obj.getStreamXadtXadtClear()));
                streamXadtAirRecycle = streamXadtAirRecycle.add(getData2(obj.getStreamXadtAirRecycle()));
                streamXadtAirClear = streamXadtAirClear.add(getData2(obj.getStreamXadtAirClear()));
                streamXadtXaztRecycle = streamXadtXaztRecycle.add(getData2(obj.getStreamXadtXaztRecycle()));
                streamXadtXaztClear = streamXadtXaztClear.add(getData2(obj.getStreamXadtXaztClear()));
                streamAirXadtSale = streamAirXadtSale.add(getData2(obj.getStreamAirXadtSale()));
                streamAirXadtRecycle = streamAirXadtRecycle.add(getData2(obj.getStreamAirXadtRecycle()));
                streamAirXadtClear = streamAirXadtClear.add(getData2(obj.getStreamAirXadtClear()));
                streamAirXixianRecycle = streamAirXixianRecycle.add(getData2(obj.getStreamAirXixianRecycle()));
                streamAirXixianClear = streamAirXixianClear.add(getData2(obj.getStreamAirXixianClear()));
                streamXaztXadtSale = streamXaztXadtSale.add(getData2(obj.getStreamXaztXadtSale()));
                streamXaztXadtRecycle = streamXaztXadtRecycle.add(getData2(obj.getStreamXaztXadtRecycle()));
                streamXaztXadtClear = streamXaztXadtClear.add(getData2(obj.getStreamXaztXadtClear()));
                streamXaztXixianRecycle = streamXaztXixianRecycle.add(getData2(obj.getStreamXaztXixianRecycle()));
                streamXaztXixianClear = streamXaztXixianClear.add(getData2(obj.getStreamXaztXixianClear()));
                failNormalAirStationSale = failNormalAirStationSale.add(getData2(obj.getFailNormalAirStationSale()));
                failNormalAirStationClear = failNormalAirStationClear.add(getData2(obj.getFailNormalAirStationClear()));
                failNormalAirOtherstationSale = failNormalAirOtherstationSale.add(getData2(obj.getFailNormalAirOtherstationSale()));
                failNormalAirOtherstationClear = failNormalAirOtherstationClear.add(getData2(obj.getFailNormalAirOtherstationClear()));
                failNormalAirTotalClear = failNormalAirTotalClear.add(getData2(obj.getFailNormalAirTotalClear()));
                failNormalXaztStationSale = failNormalXaztStationSale.add(getData2(obj.getFailNormalXaztStationSale()));
                failNormalXaztStationClear = failNormalXaztStationClear.add(getData2(obj.getFailNormalXaztStationClear()));
                failNormalXaztOtherstationSale = failNormalXaztOtherstationSale.add(getData2(obj.getFailNormalXaztOtherstationSale()));
                failNormalXaztOtherstationClear = failNormalXaztOtherstationClear.add(getData2(obj.getFailNormalXaztOtherstationClear()));
                failNormalXaztTotalClear = failNormalXaztTotalClear.add(getData2(obj.getFailNormalXaztTotalClear()));
                failSpeXadterrorSale = failSpeXadterrorSale.add(getData2(obj.getFailSpeXadterrorSale()));
                failSpeXadterrorSaleNine= failSpeXadterrorSaleNine.add(getData2(obj.getFailSpeXadterrorSaleNine()));
				failSpeXadterrorSaleSum= failSpeXadterrorSaleSum.add(getData2(obj.getFailSpeXadterrorSaleSum()));
                failSpeXadterrorClear = failSpeXadterrorClear.add(getData2(obj.getFailSpeXadterrorClear()));
                failSpeXadterrorClearNine = failSpeXadterrorClearNine.add(getData2(obj.getFailSpeXadterrorClearNine()));
                failSpeXadterrorClearSum = failSpeXadterrorClearSum.add(getData2(obj.getFailSpeXadterrorClearSum()));
                failSpeAirerrorSale = failSpeAirerrorSale.add(getData2(obj.getFailSpeAirerrorSale()));
                failSpeAirerrorClear = failSpeAirerrorClear.add(getData2(obj.getFailSpeAirerrorClear()));
                failSpeXazterrorSale = failSpeXazterrorSale.add(getData2(obj.getFailSpeXazterrorSale()));
                failSpeXazterrorClear = failSpeXazterrorClear.add(getData2(obj.getFailSpeXazterrorClear()));
                totalClear = totalClear.add(getData2(obj.getTotalClear()));

                streamXadtSale = streamXadtSale.add(getData2(obj.getStreamXadtSale()));
                streamXadtRecycle = streamXadtRecycle.add(getData2(obj.getStreamXadtRecycle()));
                streamXadtClear = streamXadtClear.add(getData2(obj.getStreamXadtClear()));
                streamAirSale = streamAirSale.add(getData2(obj.getStreamAirSale()));
                streamAirRecycle = streamAirRecycle.add(getData2(obj.getStreamAirRecycle()));
                streamAirClear = streamAirClear.add(getData2(obj.getStreamAirClear()));
                streamXaztSale = streamXaztSale.add(getData2(obj.getStreamXaztSale()));
                streamXaztRecycle = streamXaztRecycle.add(getData2(obj.getStreamXaztRecycle()));
                streamXaztClear = streamXaztClear.add(getData2(obj.getStreamXaztClear()));


                streamXaztTotalClear = streamXaztTotalClear.add(getData2(obj.getStreamXaztTotalClear()));
                streamAirTotalClear = streamAirTotalClear.add(getData2(obj.getStreamAirTotalClear()));
            }
        }

        sumSwCkClearEmergencyReturnticket.setEmeRecycle(emeRecycle.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setEmeSale(emeSale.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setEmeClear(emeClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamXadtXadtSale(streamXadtXadtSale.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamXadtXadtRecycle(streamXadtXadtRecycle.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamXadtXadtClear(streamXadtXadtClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamXadtAirRecycle(streamXadtAirRecycle.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamXadtAirClear(streamXadtAirClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamXadtXaztRecycle(streamXadtXaztRecycle.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamXadtXaztClear(streamXadtXaztClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamAirXadtSale(streamAirXadtSale.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamAirXadtRecycle(streamAirXadtRecycle.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamAirXadtClear(streamAirXadtClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamAirXixianRecycle(streamAirXixianRecycle.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamAirXixianClear(streamAirXixianClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamXaztXadtSale(streamXaztXadtSale.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamXaztXadtRecycle(streamXaztXadtRecycle.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamXaztXadtClear(streamXaztXadtClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamXaztXixianRecycle(streamXaztXixianRecycle.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamXaztXixianClear(streamXaztXixianClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailNormalAirStationSale(failNormalAirStationSale.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailNormalAirStationClear(failNormalAirStationClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailNormalAirOtherstationSale(failNormalAirOtherstationSale.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailNormalAirOtherstationClear(failNormalAirOtherstationClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailNormalAirTotalClear(failNormalAirTotalClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailNormalXaztStationSale(failNormalXaztStationSale.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailNormalXaztStationClear(failNormalXaztStationClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailNormalXaztOtherstationSale(failNormalXaztOtherstationSale.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailNormalXaztOtherstationClear(failNormalXaztOtherstationClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailNormalXaztTotalClear(failNormalXaztTotalClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailSpeXadterrorSale(failSpeXadterrorSale.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailSpeXadterrorSaleNine(failSpeXadterrorSaleNine.setScale(2,BigDecimal.ROUND_HALF_UP));
		sumSwCkClearEmergencyReturnticket.setFailSpeXadterrorSaleSum(failSpeXadterrorSaleSum.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailSpeXadterrorClear(failSpeXadterrorClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailSpeXadterrorClearNine(failSpeXadterrorClearNine.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailSpeXadterrorClearSum(failSpeXadterrorClearSum.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailSpeAirerrorSale(failSpeAirerrorSale.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailSpeAirerrorClear(failSpeAirerrorClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailSpeXazterrorSale(failSpeXazterrorSale.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setFailSpeXazterrorClear(failSpeXazterrorClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setTotalClear(totalClear.setScale(2,BigDecimal.ROUND_HALF_UP));

        sumSwCkClearEmergencyReturnticket.setStreamXadtSale(streamXadtSale.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamXadtRecycle(streamXadtRecycle.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamXadtClear(streamXadtClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamAirSale(streamAirSale.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamAirRecycle(streamAirRecycle.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamAirClear(streamAirClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamXaztSale(streamXaztSale.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamXaztRecycle(streamXaztRecycle.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamXaztClear(streamXaztClear.setScale(2,BigDecimal.ROUND_HALF_UP));


        sumSwCkClearEmergencyReturnticket.setStreamXaztTotalClear(streamXaztTotalClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        sumSwCkClearEmergencyReturnticket.setStreamAirTotalClear(streamAirTotalClear.setScale(2,BigDecimal.ROUND_HALF_UP));
        return sumSwCkClearEmergencyReturnticket;
    }

	 /**
     * 应急纸票和退换票正常清分操作（按月）
     * @param startDate  当月的开始日期
     * @param endDate    当月的结束日期
     * @return
     */
	@Override
    public Boolean generateSwCkClearEmergencyReturnTicket(String startDate, String endDate){
    	Map<String,String> mapLineClearRule = swCkClearRuleService.selectRulesDetailsMapByDate(startDate, endDate) ; 
        List<Map<String,String>> listLine = this.baseMapper.selectLineObjList(startDate,endDate);
        
        //遍历线路是存储组织的数据 
        List<SwCkClearEmergencyReturnticket>  listAllSave = new ArrayList<>();
        Map<String,SwCkClearEmergencyReturnticket> mapSaveData= new HashMap<>();
        //车站录入的通用数据信息
        List<Map<String,String>> listWorkOtherMap = this.baseMapper.getInputPassengerWorkOtherMap(startDate,endDate);
        
        //车站录入的特殊退票数据信息
        List<Map<String,String>> listWorkOtherSpecialMap = this.baseMapper.getInputPassengerWorkOtherSpecialReturnMap(startDate,endDate);
		
		//西安地铁各个车站的售卖的应急纸票金额
    	List<Map<String,String>>  listXadtStationSale = this.baseMapper.getEmergencyXadtSale(startDate,endDate);
              
    	//导入的应急纸票查询
    	List<Map<String,String>> listImportEmergencyMap= this.baseMapper.getImportMapEmergencyTicket(startDate, endDate);
        //导入的退换票
    	List<Map<String,String>> listImportReturnMap= this.baseMapper.getImportMapReturnTicket(startDate, endDate);
    	/*  待清分金额暂时不用查询
    	// 2.1应急纸票大客流 西安地铁-西咸的待清分金额 减去14和9号线的
        Map<String,String>  streamWaitSumXadtAndXian = this.baseMapper.getEmergencyBigStream_WaitSum_XadtAndXixian(startDate, endDate);
        // 2.2应急纸票大客流 西安地铁(不含西咸)-机场的待清分金额
        Map<String,String>  streamWaitSumXadtAndAir = this.baseMapper.getEmergencyBigStream_WaitSum_XadtAndAir(startDate, endDate);
        
        // 2.3应急纸票大客流 西安地铁-西咸-机场的待清分金额
        Map<String,String>  streamWaitSumXadtAndXianAndAir = this.baseMapper.getEmergencyBigStream_WaitSum_XadtAndXixianAndAir(startDate, endDate);
        
        // 2.4应急纸票大客流 西安地铁(不含西咸)-西安中铁的待清分金额
        Map<String,String>  streamWaitSumXadtAndXazt = this.baseMapper.getEmergencyBigStream_WaitSum_XadtAndXazt(startDate, endDate);
        
        // 2.5应急纸票大客流 西安地铁-西咸-西安中铁的待清分金额
        Map<String,String>  streamWaitSumXadtAndXianAndXazt = this.baseMapper.getEmergencyBigStream_WaitSum_XadtAndXixianAndXazt(startDate, endDate);
		*/
    	
    	//应急纸票误出站  机场城际回收金额
        BigDecimal sumA2_1 = new BigDecimal("0");
    	//应急纸票误出站  西安地铁-机场城际 西安地铁回收金额合计
        BigDecimal sumA1_1 = new BigDecimal("0");
    	
    	//正常情况退票  西安地铁-机场城际-西安地铁线路退北客站北广场购买车票金额合计
        BigDecimal sumB1_1 = new BigDecimal("0");
    	
    	//正常情况退款-西安地铁-机场城际-机场城际线路退北客站北广场购买车票金额
        BigDecimal sumB2_1 = new BigDecimal("0");
    	
        //正常情况退款-西安地铁-机场城际-机场城际线路退其他车站购买车票金额
        BigDecimal sumB2_3 = new BigDecimal("0");
    	
    	//正常情况退款-西安地铁-西安中铁-西安地铁线路退纺织城购买车票金额
        BigDecimal sumB3_1 = new BigDecimal("0");
    	
    	//正常情况退款-西安地铁-西安中铁-西安中铁线路退纺织城购买车票金额
        BigDecimal sumB4_1 = new BigDecimal("0");
    	
        //正常情况退款-西安地铁-西安中铁-西安中铁线路退其他车站购买车票金额
        BigDecimal sumB4_3 = new BigDecimal("0");
    	
    	//应急纸票大客流-西安地铁-机场-机场线路回收金额
        BigDecimal sumD2_3 = new BigDecimal("0");
    	
    	//应急纸票大客流-西安地铁-西安中铁-西安中铁线路回收金额
        BigDecimal sumD4_3 = new BigDecimal("0");  	   
        
        //特殊情况退款（故障退款）-西安地铁-机场城际-西安地铁线路-机场城际故障退款金额
        BigDecimal sumC1_1 = new BigDecimal("0");
    	//特殊情况退款（故障退款）-西安地铁-机场城际-机场城际线路-机场城际故障退款金额  导入
        BigDecimal sumC2_1 = new BigDecimal("0");
    	//特殊情况退款（故障退款）-西安地铁-机场城际-机场城际线路-西安地铁故障退款金额  导入
        BigDecimal sumC2_3 = new BigDecimal("0");
    	
    	//特殊情况退款（故障退款）-西安地铁-西安中铁-西安地铁线路-西安中铁故障退款金额
        BigDecimal sumC3_1 = new BigDecimal("0");
    	//特殊情况退款（故障退款）-西安地铁-西安中铁-西安地铁线路-西安地铁故障退款金额
        BigDecimal sumC3_3 = new BigDecimal("0");
    	
    	//特殊情况退款（故障退款）-西安地铁-西安中铁-西安中铁线路-西安中铁故障退款金额  导入
        BigDecimal sumC4_1 = new BigDecimal("0");
    	//特殊情况退款（故障退款）-西安地铁-西安中铁-西安中铁线路-西安地铁故障退款金额  导入
        BigDecimal sumC4_3 = new BigDecimal("0");
    	//----------------------20210819 新增开始--------------------------------------------------------------------
    	//大客流  西安地铁内部发售的应急纸票（不包括西咸）
        BigDecimal sumD1_6 = new BigDecimal("0");
        BigDecimal sumD2_1 = new BigDecimal("0");
        BigDecimal sumD3_3 = new BigDecimal("0");
        BigDecimal sumD1_3 = new BigDecimal("0");
        BigDecimal sumD5_7 = new BigDecimal("0");

		BigDecimal sumD5_3 = new BigDecimal("0");

		//9和14号线机场线发售大客流
		BigDecimal sumD14_3 = new BigDecimal("0");
		BigDecimal sumD9_3 = new BigDecimal("0");
        //西安地铁回收9和14大客流
		BigDecimal sumD14_16_1 = new BigDecimal("0");
		BigDecimal sumD9_16_1 = new BigDecimal("0");
		Map<String,String> mapD14_16_1 = new HashMap<>(); 
		Map<String,String> mapD9_16_1 = new HashMap<>();		
		
    	    	
    	Map<String,String> mapD5_7 = new HashMap<>(); 
    	//应急纸票大客流-西安地铁录发售的自己的内部的大客流
    	Map<String,String> mapD1_6 = new HashMap<>();
    	//应急纸票大客流-西安地铁录（西咸）发售的自己的内部的大客流
    	Map<String,String> mapD1_9 = new HashMap<>();
    	//-----------------------20210819 新增结束
    	//应急纸票误出站回收金额--西安地铁-机场城际-西安地铁线路回收金额
    	Map<String,String> mapA1_1 = new HashMap<>();
    	//应急纸票误出站回收金额--西安地铁-机场城际-西安地铁线路发售金额
    	Map<String,String> mapA1_2 = new HashMap<>();
    	
    	
    	//正常情况退款-西安地铁-机场城际-西安地铁线路退北客站北广场购买车票金额
    	Map<String,String> mapB1_1 = new HashMap<>();
    	//正常情况退款-西安地铁-机场城际-西安地铁线路退其他车站购买车票金额
    	Map<String,String> mapB1_3 = new HashMap<>();
    	
    	
    	//正常情况退款-西安地铁-西安中铁-西安地铁线路退纺织城购买车票金额
    	Map<String,String> mapB3_1 = new HashMap<>();    	
    	//正常情况退款-西安地铁-西安中铁-西安地铁线路退其他车站购买车票金额
    	Map<String,String> mapB3_3 = new HashMap<>();
    	
    	
    	//应急纸票大客流-西安地铁-西咸-西安地铁线路回收金额
    	Map<String,String> mapD1_1 = new HashMap<>();
    	//应急纸票大客流-西安地铁-西咸-西咸线路回收金额
    	Map<String,String> mapD1_3 = new HashMap<>();
    	
    	//应急纸票大客流-西安地铁-机场城际-西安地铁线路回收金额
    	Map<String,String> mapD2_1 = new HashMap<>();
    	
    	//应急纸票大客流-西安地铁-西咸-机场城际-西咸线路回收金额
    	Map<String,String> mapD3_3 = new HashMap<>();
    	
    	//应急纸票大客流-西安地铁-西安中铁-西安地铁线路回收金额
    	Map<String,String> mapD4_1 = new HashMap<>();
    	
    	//应急纸票大客流-西安地铁-西咸-西安中铁-西咸线路回收金额
    	Map<String,String> mapD5_3 = new HashMap<>();
    	
    	
    	//故障退款-西安地铁-机场城际-西安地铁线路-机场城际故障退款金额
    	Map<String,String> mapC1_1 = new HashMap<>();    	
    	    	
    	//特殊情况退款（故障退款）-西安地铁-西安中铁-西安地铁线路-西安中铁故障退款金额
    	Map<String,String> mapC3_1 = new HashMap<>();    	
    	//特殊情况退款（故障退款）-西安地铁-西安中铁-西安地铁线路-西安地铁故障退款金额
    	Map<String,String> mapC3_3 = new HashMap<>(); 

		//TODO 遍历  listXadtStationSale
    	/*
    	 * stream计算所有amount的合计值，赋值给 sumD1_6
    	 * */
        for (Map<String, String> map : listXadtStationSale) {
            BigDecimal amount = new BigDecimal(map.get("amount"));
            sumD1_6 = sumD1_6.add(amount);
        }
    	//TODO 遍历应急纸票 listImportEmergencyMap 遍历
    	/*
    	 * 1. 取lineCode=54,reportType=1，projectItem=2 ，所有金额合计到sumA2_1    机场城际导入的误出站
    	 * 2. 取lineCode=54，reportType=2，projectItem=2  ，所有金额合计到sumD2_3  机场城际导入的大客流
    	 * 3. 取lineCode=9，reportType=2，projectItem=2  ，所有金额合计到sumD4_3  9号线导入的大客流
    	 *   
    	 */
        for (Map<String, String> map : listImportEmergencyMap) {
            String lineCode = map.get("lineCode");
            String reportType = map.get("reportType");
            String projectItem = map.get("projectItem");
            if("54".equals(lineCode) && "1".equals(reportType) && "2".equals(projectItem)){//回收西安地铁误出站
                BigDecimal amount = new BigDecimal(map.get("amount"));
                sumA2_1 = sumA2_1.add(amount);
            }
            if("54".equals(lineCode) && "2".equals(reportType) && "2".equals(projectItem)){//回收西安地铁大客流
                BigDecimal amount = new BigDecimal(map.get("amount"));
                sumD2_3 = sumD2_3.add(amount);
            }
			if("54".equals(lineCode) && "2".equals(reportType) && "1".equals(projectItem)){//发售大客流
                BigDecimal amount = new BigDecimal(map.get("amount"));
                sumD14_3 = sumD14_3.add(amount);
            }
			if("9".equals(lineCode) && "2".equals(reportType) && "1".equals(projectItem)){//发售大客流
                BigDecimal amount = new BigDecimal(map.get("amount"));
                sumD9_3 = sumD9_3.add(amount);
            }
			
            if("9".equals(lineCode) && "2".equals(reportType) && "2".equals(projectItem)){
                BigDecimal amount = new BigDecimal(map.get("amount"));
                sumD4_3 = sumD4_3.add(amount);
            }
        }
    	//TODO 遍历退换票 listImportReturnMap 遍历
    	/*reportType=1 正常退款   2 特殊退款
    	 * 1. 取lineCode=54,reportType是1，SERVICE_ORG不是西安地铁1 ，所有金额合计到sumB2_1 不属于西安地铁故障导致的正常情况退款
    	 * 2. 取lineCode=54,reportType是1，SERVICE_ORG 是西安地铁1，所有金额合计到sumB2_3     西安地铁故障导致正常情况退款
    	 * 3. 取lineCode=54,reportType是2，SERVICE_ORG不是西安地铁1 ，所有金额合计到sumC2_1  
    	 * 4. 取lineCode=54,reportType是2，SERVICE_ORG 是西安地铁1，所有金额合计到sumC2_3     西安地铁故障导致特殊情况退款
    	 * 5. 取lineCode=9,reportType是2，SERVICE_ORG不是西安地铁1 ，所有金额合计到sumC4_1
    	 * 6. 取lineCode=9,reportType是2，SERVICE_ORG 是西安地铁1，所有金额合计到sumC4_3   9号线导入的西安地铁故障导致特殊情况退款
    	
    	 */
        for (Map<String, String> map : listImportReturnMap) {
            String lineCode = map.get("lineCode");
            String reportType = map.get("reportType");
            String serviceOrg = map.get("serviceOrg");
            if("54".equals(lineCode) && "1".equals(reportType) && !"1".equals(serviceOrg)){
                BigDecimal amount = new BigDecimal(map.get("amount"));
                sumB2_1 = sumB2_1.add(amount);
            }
            if("54".equals(lineCode) && "1".equals(reportType) && "1".equals(serviceOrg)){
                BigDecimal amount = new BigDecimal(map.get("amount"));
                sumB2_3 = sumB2_3.add(amount);
            }
			if("9".equals(lineCode) && "1".equals(reportType) && !"1".equals(serviceOrg)){
                BigDecimal amount = new BigDecimal(map.get("amount"));
                sumB4_1 = sumB4_1.add(amount);
            }
            if("9".equals(lineCode) && "1".equals(reportType) && "1".equals(serviceOrg)){
                BigDecimal amount = new BigDecimal(map.get("amount"));
                sumB4_3 = sumB4_3.add(amount);
            }
            if("54".equals(lineCode) && "2".equals(reportType) && !"1".equals(serviceOrg)){//机场自己故障导致的退款 sumC2_1
                BigDecimal amount = new BigDecimal(map.get("amount"));
                sumC2_1 = sumC2_1.add(amount);
            }
            if("54".equals(lineCode) && "2".equals(reportType) && "1".equals(serviceOrg)){//西安地铁故障导致的退款 sumC2_3
                BigDecimal amount = new BigDecimal(map.get("amount"));
                sumC2_3 = sumC2_3.add(amount);
            }
            if("9".equals(lineCode) && "2".equals(reportType) && !"1".equals(serviceOrg)){//9号线自己故障导致的退款sumC4_1
                BigDecimal amount = new BigDecimal(map.get("amount"));
                sumC4_1 = sumC4_1.add(amount);
            }
            if("9".equals(lineCode) && "2".equals(reportType) && "1".equals(serviceOrg)){//西安地铁故障导致的退款sumC4_3
                BigDecimal amount = new BigDecimal(map.get("amount"));
                sumC4_3 = sumC4_3.add(amount);
            }
			
        }
    	//TODO 遍历车站录入 listWorkOtherMap 遍历  1,1,2
    	
    	/*
    	 
    	 * 故障/发售运营商：failure_Operator  1：西安地铁  2：机场城际   3：其他  4:西安中铁
    	 * 出站/进站运营商：sell_Operator  1：西安地铁  2：机场城际   3：其他  4:西安中铁
    	 * 数据类型：data_type  1：发售应急纸票  2：正常情况退款   3：特殊情况退票
    	 * 产生原因：happen_cause:1.因误出站发售应急纸票 2:因大客流发售前往西安地铁应急纸票  3:因误出站回收应急纸票 4:因大客流回收前往西安地铁应急纸票 5:因大客流发售前往其他运营商应急纸票 6:因大客流回收前往其他运营商应急纸票
    	 *                       7.运营故障导致（单程票、二维码电子车票、应急纸票等）退款  8:非纺织城站购买（单程票、应急纸票）在西安地铁退票  9:纺织城站购买（单程票、应急纸票）在西安地铁退票
    	 *                       选择西安地铁时，原来需求中要求删除2和5
		 *   3,4,6,7,8，9清分结果后，将金额累加到运营商收入清分报表中。一般一个月月底生成后才累加  TODO。
    	 * 1. 查询运营商机场城际，	failure_Operator='2' data_type='1'  HAPPEN_CAUSE='3'  serviceId ='1' 
    	 *    赋值 mapA1_1  key ：线路编号  value：金额 
    	 * 2. 将所有线路金额合计值赋值给变量  sumA1_1 ，条件同1。
    	 * 3. failure_Operator='1' data_type='1'  HAPPEN_CAUSE='1' serviceId ='1' lineCode!='4'  serviceId ='1' 
    	 *    赋值mapA1_2 key ：线路编号  value：金额 
    	 * 4. 查询运营商机场城际  failure_Operator='2' data_type='2'  HAPPEN_CAUSE='9'   serviceId ='1' 
    	 *    赋值 mapB1_1  key ：线路编号  value：金额  
    	 * 5. 将所有线路金额合计值赋值给变量sumB1_1，条件同4
    	 * 
    	 * 6. 查询运营商机场城际  failure_Operator='2' data_type='2'  HAPPEN_CAUSE='8'  退非北客站    serviceId ='1' 
    	 *    赋值 mapB1_3  key ：线路编号  value：金额    
    	 * 
    	 * 7. 查询运营商西安中铁  failure_Operator='4' data_type='2'  HAPPEN_CAUSE='9'  退纺织城    serviceId ='1' 
    	 *    赋值 mapB3_1  key ：线路编号  value：金额 
    	 * 8. 将所有线路金额合计值赋值给变量sumB3_1，条件同7  
    	 * 9. 查询运营商西安中铁  failure_Operator='4' data_type='2'  HAPPEN_CAUSE='8'  退非纺织城  serviceId ='1'
    	 *    赋值 mapB3_3  key ：线路编号  value：金额  
    	 *10. 查询运营商西安地铁    failure_Operator='1' data_type='1'  HAPPEN_CAUSE='4'  serviceId ='1'  大客流回收前往西安地铁应急纸票
    	 *    赋值 mapD1_1  key ：线路编号  value：金额      
    	 *11. 查询运营商西咸     failure_Operator='4' data_type='1'  HAPPEN_CAUSE='4'  serviceId ='1'  大客流回收前往西安地铁应急纸票
    	 *    赋值 mapD1_3  key ：线路编号  value：金额         
    	 *12. 将所有线路金额合计值赋值给变量sumD1_3，条件同11
    	 *13. 查询运营商西安地铁   failure_Operator='2' data_type='1'  HAPPEN_CAUSE='4'    serviceId='1' 
    	 *    赋值 mapD2_1  key ：线路编号  value：金额     -
    	 *14. 将所有线路金额合计值赋值给变量sumD2_1，条件同12   
    	 *15.查询运营商机场城际   failure_Operator='2' data_type='1'  HAPPEN_CAUSE='6'  serviceId='71'  
    	 *     赋值 mapD3_3  key ：线路编号  value：金额  
    	 *16.将所有线路金额合计值赋值给变量sumD3_3，条件同15      
    	 *17.查询运营商西安地铁   failure_Operator='1' data_type='1'  HAPPEN_CAUSE='4'     serviceId='1' 
    	 *     赋值 mapD4_1  key ：线路编号  value：金额   
    	 *18.查询运营商西安中铁   failure_Operator='4' data_type='1'  HAPPEN_CAUSE='6'   serviceId='71'   大客流回收前往其他运营商应急纸票，录入车站是西咸的线路  
    	 *     赋值 mapD5_3  key ：线路编号  value：金额     
    	 *19. 查询运营商机场城际  failure_Operator='2' data_type='3'  HAPPEN_CAUSE='7'    serviceId='1' 
    	 *     赋值 mapC1_1  key ：线路编号  value：金额
    	 *20. 将所有线路金额合计值赋值给变量sumC1_1，条件同19
    	 *21. 查询运营商西安地铁  failure_Operator='1' data_type='3'  HAPPEN_CAUSE='7'  serviceId='1' 
    	 *     赋值 mapC1_3  key ：线路编号  value：金额
    	 *22. 将所有线路金额合计值赋值给变量sumC1_3，条件同21  
    	 *23. 查询运营商西安中铁  failure_Operator='4' data_type='3'  HAPPEN_CAUSE='7'     serviceId='1' 
    	 *     赋值 mapC3_1  key ：线路编号  value：金额
    	 *24. 将所有线路金额合计值赋值给变量sumC3_1，条件同23 
    	 *25. 查询运营商西安地铁 failure_Operator='1' data_type='3'  HAPPEN_CAUSE='7'  serviceId='1' 
    	 *     赋值 mapC3_3  key ：线路编号  value：金额
    	 *26. 将所有线路金额合计值赋值给变量sumC3_3，条件同25
    	 *27. 查询运营商西咸     failure_Operator='4' data_type='1'  HAPPEN_CAUSE='4'  serviceId ='71'  大客流回收前往西安地铁应急纸票
    	 *    赋值 mapD5_7  key ：线路编号  value：金额         --------需要增加sumD5_7的值 TODO
    	 *28. 将所有线路金额合计值赋值给变量sumD5_7，条件同27     
    	 */
        for (Map<String, String> map : listWorkOtherMap) {
            String failureOperator = map.get("failureOperator");
            String dataType = map.get("dataType");
            String happenCause = map.get("happenCause");
            String serviceId = map.get("serviceId");
            String lineCode = map.get("lineCode");
            //1. 查询运营商机场城际，	failure_Operator='2' data_type='1'  HAPPEN_CAUSE='3'  serviceId ='1'
            //赋值 mapA1_1  key ：线路编号  value：金额
            //2. 将所有线路金额合计值赋值给变量  sumA1_1 ，条件同1。
            if("2".equals(failureOperator) && "1".equals(dataType) && "3".equals(happenCause) && "1".equals(serviceId)){
                String amount = map.get("amount");
                mapA1_1.put(lineCode,amount);
                sumA1_1 = sumA1_1.add(new BigDecimal(amount));
            }
            //3. failure_Operator='1' data_type='1'  HAPPEN_CAUSE='1' serviceId ='1' lineCode!='4'  serviceId ='1'
            //赋值mapA1_2 key ：线路编号  value：金额
            if("1".equals(failureOperator) && "1".equals(dataType) && "1".equals(happenCause) && !"4".equals(lineCode) && "1".equals(serviceId)){
                String amount = map.get("amount");
                mapA1_2.put(lineCode,amount);
            }
            //4. 查询运营商机场城际  failure_Operator='2' data_type='2'  HAPPEN_CAUSE='9'   serviceId ='1'
            //赋值 mapB1_1  key ：线路编号  value：金额
            //5. 将所有线路金额合计值赋值给变量sumB1_1，条件同4
            if("2".equals(failureOperator) && "2".equals(dataType) && "9".equals(happenCause) && "1".equals(serviceId)){
                String amount = map.get("amount");
                mapB1_1.put(lineCode,amount);
                sumB1_1 = sumB1_1.add(new BigDecimal(amount));
            }
            //6. 查询运营商机场城际  failure_Operator='2' data_type='2'  HAPPEN_CAUSE='8'  退非北客站    serviceId ='1'
            //赋值 mapB1_3  key ：线路编号  value：金额
            if("2".equals(failureOperator) && "2".equals(dataType) && "8".equals(happenCause) && "1".equals(serviceId)){
                String amount = map.get("amount");
                mapB1_3.put(lineCode,amount);
            }
            //7. 查询运营商西安中铁  failure_Operator='4' data_type='2'  HAPPEN_CAUSE='9'  退纺织城    serviceId ='1'
            //赋值 mapB3_1  key ：线路编号  value：金额
            //8. 将所有线路金额合计值赋值给变量sumB3_1，条件同7
            if("4".equals(failureOperator) && "2".equals(dataType) && "9".equals(happenCause) && "1".equals(serviceId)){
                String amount = map.get("amount");
                mapB3_1.put(lineCode,amount);
                sumB3_1 = sumB3_1.add(new BigDecimal(amount));
            }
            //9. 查询运营商西安中铁  failure_Operator='4' data_type='2'  HAPPEN_CAUSE='8'  退非纺织城  serviceId ='1'
            //赋值 mapB3_3  key ：线路编号  value：金额
            if("4".equals(failureOperator) && "2".equals(dataType) && "8".equals(happenCause) && "1".equals(serviceId)){
                String amount = map.get("amount");
                mapB3_3.put(lineCode,amount);
            }
            //10. 查询运营商西安地铁    failure_Operator='1' data_type='1'  HAPPEN_CAUSE='4'  serviceId ='1'  大客流回收前往西安地铁应急纸票
            //赋值 mapD1_1  key ：线路编号  value：金额
            if("1".equals(failureOperator) && "1".equals(dataType) && "4".equals(happenCause) && "1".equals(serviceId)){
                String amount = map.get("amount");
                mapD1_1.put(lineCode,amount);
            }
            //11. 查询运营商西咸     failure_Operator='4' data_type='1'  HAPPEN_CAUSE='4'  serviceId ='1'  大客流回收前往西安地铁应急纸票
            //赋值 mapD1_3  key ：线路编号  value：金额
            //12. 将所有线路金额合计值赋值给变量sumD1_3，条件同11
            if("4".equals(failureOperator) && "1".equals(dataType) && "4".equals(happenCause) && "1".equals(serviceId)){
                String amount = map.get("amount");
                mapD1_3.put(lineCode,amount);
                sumD1_3 = sumD1_3.add(new BigDecimal(amount));
            }
            //13. 查询运营商西安地铁   failure_Operator='2' data_type='1'  HAPPEN_CAUSE='4'    serviceId='1'
            //赋值 mapD2_1  key ：线路编号  value：金额     -
    	    //14. 将所有线路金额合计值赋值给变量sumD2_1，条件同13 todo 需要确认条件是同12还是13
            if("2".equals(failureOperator) && "1".equals(dataType) && "4".equals(happenCause) && "1".equals(serviceId)){
                String amount = map.get("amount");
                mapD2_1.put(lineCode,amount);
                sumD2_1 = sumD2_1.add(new BigDecimal(amount));
            }
            //15.查询运营商机场城际   failure_Operator='2' data_type='1'  HAPPEN_CAUSE='6'  serviceId='71'
            //赋值 mapD3_3  key ：线路编号  value：金额
            //16.将所有线路金额合计值赋值给变量sumD3_3，条件同15
            if("2".equals(failureOperator) && "1".equals(dataType) && "6".equals(happenCause) && "71".equals(serviceId)){
                String amount = map.get("amount");
                mapD3_3.put(lineCode,amount);
                sumD3_3 = sumD3_3.add(new BigDecimal(amount));
            }
			//16_1.将所有线路金额合计值赋值给变量sumD14_16_1
            if("2".equals(failureOperator) && "1".equals(dataType) && "6".equals(happenCause) && "1".equals(serviceId)){
                String amount = map.get("amount");
                mapD14_16_1.put(lineCode,amount);
                sumD14_16_1 = sumD14_16_1.add(new BigDecimal(amount));
            }
            //17.查询运营商西安地铁   failure_Operator='1' data_type='1'  HAPPEN_CAUSE='4'     serviceId='1'
            //赋值 mapD4_1  key ：线路编号  value：金额
            if("1".equals(failureOperator) && "1".equals(dataType) && "4".equals(happenCause) && "1".equals(serviceId)){
                String amount = map.get("amount");
                mapD4_1.put(lineCode,amount);
            }
            //18.查询运营商西安中铁   failure_Operator='4' data_type='1'  HAPPEN_CAUSE='6'   serviceId='71'   大客流回收前往其他运营商应急纸票，录入车站是西咸的线路
            //赋值 mapD5_3  key ：线路编号  value：金额
            if("4".equals(failureOperator) && "1".equals(dataType) && "6".equals(happenCause) && "71".equals(serviceId)){
                String amount = map.get("amount");
                mapD5_3.put(lineCode,amount);
				sumD5_3 = sumD5_3.add(new BigDecimal(amount));
            }
			if("4".equals(failureOperator) && "1".equals(dataType) && "6".equals(happenCause) && "1".equals(serviceId)){//西安地铁回收9号线大客流
                String amount = map.get("amount");
                mapD9_16_1.put(lineCode,amount);
                sumD9_16_1 = sumD9_16_1.add(new BigDecimal(amount));
            }
            //19. 查询运营商机场城际  failure_Operator='2' data_type='3'  HAPPEN_CAUSE='7'    serviceId='1'
            //赋值 mapC1_1  key ：线路编号  value：金额
            //20. 将所有线路金额合计值赋值给变量sumC1_1，条件同19
            if("2".equals(failureOperator) && "3".equals(dataType) && "7".equals(happenCause) && "1".equals(serviceId)){
                String amount = map.get("amount");
                mapC1_1.put(lineCode,amount);
                sumC1_1 = sumC1_1.add(new BigDecimal(amount));
            }
            
            //23. 查询运营商西安中铁  failure_Operator='4' data_type='3'  HAPPEN_CAUSE='7'     serviceId='1'
            //赋值 mapC3_1  key ：线路编号  value：金额
            //24. 将所有线路金额合计值赋值给变量sumC3_1，条件同23
            if("4".equals(failureOperator) && "3".equals(dataType) && "7".equals(happenCause) && "1".equals(serviceId)){
                String amount = map.get("amount");
                mapC3_1.put(lineCode,amount);
                sumC3_1 = sumC3_1.add(new BigDecimal(amount));
            }
            //25. 查询运营商西安地铁 failure_Operator='1' data_type='3'  HAPPEN_CAUSE='7'  serviceId='1'
            //赋值 mapC3_3  key ：线路编号  value：金额
            //26. 将所有线路金额合计值赋值给变量sumC3_3，条件同25
            if("1".equals(failureOperator) && "3".equals(dataType) && "7".equals(happenCause) && "1".equals(serviceId)){
                String amount = map.get("amount");
                mapC3_3.put(lineCode,amount);
                sumC3_3 = sumC3_3.add(new BigDecimal(amount));
            }
            //27. 查询运营商西咸     failure_Operator='4' data_type='1'  HAPPEN_CAUSE='4'  serviceId ='71'  大客流回收前往西安地铁应急纸票
            //赋值 mapD5_7  key ：线路编号  value：金额
    	    //28. 将所有线路金额合计值赋值给变量sumD5_7，条件同27
            if("4".equals(failureOperator) && "1".equals(dataType) && "4".equals(happenCause) && "71".equals(serviceId)){
                String amount = map.get("amount");
                mapD5_7.put(lineCode,amount);
                sumD5_7 = sumD5_7.add(new BigDecimal(amount));
            }
        }
        /* 特殊情况退票获取对应的值
      	 
    	 * 故障/发售运营商：failure_Operator  1：西安地铁  2：机场城际   3：其他  4:西安中铁
    	 * 出站/进站运营商：sell_Operator  1：西安地铁  2：机场城际   3：其他  4:西安中铁
    	 * 数据类型：data_type  1：发售应急纸票  2：正常情况退款   3：特殊情况退票
    	 * 产生原因：happen_cause:1.因误出站发售应急纸票 2:因大客流发售前往西安地铁应急纸票  3:因误出站回收应急纸票 4:因大客流回收前往西安地铁应急纸票 5:因大客流发售前往其他运营商应急纸票 6:因大客流回收前往其他运营商应急纸票
    	 *                       7.运营故障导致（单程票、二维码电子车票、应急纸票等）退款  8:非纺织城站购买（单程票、应急纸票）在西安地铁退票  9:纺织城站购买（单程票、应急纸票）在西安地铁退票
    	 *                       选择西安地铁时，原来需求中要求删除2和5
    	 */     
     
    	//特殊情况退款（故障退款）-西安地铁内部故障---退14号线款金额  录入
        BigDecimal sumC1_3 = new BigDecimal("0");
        
        //特殊情况退款（故障退款）-西安地铁内部故障--退9号线款金额 录入
        BigDecimal sumC1_4 = new BigDecimal("0"); 
        
        //特殊情况退款（故障退款）-14机场故障---退西安地铁线款金额  录入 退的是西安地铁发售的钱
        BigDecimal sumC1_E14_XADT = new BigDecimal("0");
        
        //特殊情况退款（故障退款）--9号线故障---退西安地铁线款金额  录入 退的是西安地铁发售的钱
        BigDecimal sumC1_E9_XADT = new BigDecimal("0"); 
        
        
        
       //车站录入，故障运营商是西安地铁，但退的是14号线发售的票
    	Map<String,String> mapC1_3 = new HashMap<>(); //退14
      	Map<String,String> mapC1_4 = new HashMap<>(); //退9
      	
      	//车站录入 故障运营商是机场或者9号线，但退的是西安地铁发售的票
      	Map<String,String> mapC1_E14_XADT = new HashMap<>(); 
      	Map<String,String> mapC1_E9_XADT = new HashMap<>();       
        
      	 /* 特殊情况退票获取对应的值
      	 
    	 * 故障/发售运营商：failure_Operator  1：西安地铁  2：机场城际   3：其他  4:西安中铁
    	 * 出站/进站运营商：sell_Operator  1：西安地铁  2：机场城际   3：其他  4:西安中铁
    	 * 数据类型：data_type  1：发售应急纸票  2：正常情况退款   3：特殊情况退票
    	 * 产生原因：happen_cause:1.因误出站发售应急纸票 2:因大客流发售前往西安地铁应急纸票  3:因误出站回收应急纸票 4:因大客流回收前往西安地铁应急纸票 5:因大客流发售前往其他运营商应急纸票 6:因大客流回收前往其他运营商应急纸票
    	 *                       7.运营故障导致（单程票、二维码电子车票、应急纸票等）退款  8:非纺织城站购买（单程票、应急纸票）在西安地铁退票  9:纺织城站购买（单程票、应急纸票）在西安地铁退票
    	 *                       选择西安地铁时，原来需求中要求删除2和5
    	 */
       for (Map<String, String> map : listWorkOtherSpecialMap) {
            String failureOperator = map.get("failureOperator");
            String sellOperator = map.get("sellOperator");
            String dataType = map.get("dataType");
            String happenCause = map.get("happenCause");
            String serviceId = map.get("serviceId");
            String lineCode = map.get("lineCode");
            //1. 查询西安地铁故障，退的是机场城际的钱 求和包括西咸            
           if("1".equals(failureOperator) && "2".equals(sellOperator) && "3".equals(dataType) && "7".equals(happenCause) && ("1".equals(serviceId) || "71".equals(serviceId)|| "72".equals(serviceId))){
        	  String amount = map.get("amount");
        	  mapC1_3.put(lineCode,amount);
        	  sumC1_3 = sumC1_3.add(new BigDecimal(amount));
           }
           //1. 查询西安地铁故障，退的是9号线的钱       求和包括西咸    
           if("1".equals(failureOperator) && "4".equals(sellOperator) && "3".equals(dataType) && "7".equals(happenCause) && ("1".equals(serviceId) || "71".equals(serviceId)|| "72".equals(serviceId))){
         	  String amount = map.get("amount");
         	  mapC1_4.put(lineCode,amount);
         	  sumC1_4 = sumC1_4.add(new BigDecimal(amount));
            }
           //1. 查询机场城际故障，进站是机场城际            
           if("2".equals(failureOperator) && "2".equals(sellOperator) && "3".equals(dataType) && "7".equals(happenCause) && ("1".equals(serviceId) || "71".equals(serviceId)|| "72".equals(serviceId))){
        	  String amount = map.get("amount");
        	  mapC1_E14_XADT.put(lineCode,amount);
        	  sumC1_E14_XADT = sumC1_E14_XADT.add(new BigDecimal(amount));
           }
           //1. 查询9故障，进站是9号线       
           if("4".equals(failureOperator) && "4".equals(sellOperator) && "3".equals(dataType) && "7".equals(happenCause) && ("1".equals(serviceId) || "71".equals(serviceId)|| "72".equals(serviceId))){
        	  String amount = map.get("amount");
        	  mapC1_E9_XADT.put(lineCode,amount);
        	  sumC1_E9_XADT = sumC1_E9_XADT.add(new BigDecimal(amount));
           }           
       }
       
       //设置默认值
       BigDecimal decimal = new BigDecimal("0");
       BigDecimal decimal100 = new BigDecimal("100");
       BigDecimal decimal10000 = new BigDecimal("10000");
       int scale5 = 5;
       //一、---------------------------待清分金额---特殊退款，算出各个故障的总的待清分金额
       //1.西安地铁故障导致的退款 西安地铁录入+机场导入
       BigDecimal sum_xadterror_all_14 = new BigDecimal("0"); 
       sum_xadterror_all_14 = sumC1_3.add(sumC2_3);
       
       //2.西安地铁故障导致的退款 西安地铁录入+9号线导入
       BigDecimal sum_xadterror_all_9 = new BigDecimal("0"); 
       sum_xadterror_all_9 = sumC1_4.add(sumC4_3);

	   LOGGER.info("西安地铁故障  总的待清分金额== 14=="+sum_xadterror_all_14+"====9号线======="+sum_xadterror_all_9);
       
       //待清分金额总计计算
       
       //1.西安地铁故障--地铁与机场--西安地铁待清分金额合计
       String  keyErrorXadtAir_Xadt = SwCkClearRuleConstans.CLEAR_RULE_RETURN_ERROR+","+"1"+","+SwCkClearRuleConstans.SERVICE_ID_XADT;//到运营商级即可
       String  keyErrorXadtAir_Air = SwCkClearRuleConstans.CLEAR_RULE_RETURN_ERROR+","+"1"+","+SwCkClearRuleConstans.SERVICE_ID_AIR;//到运营商级即可
       
       //谁大取谁
       String keyErrorXadtAir = Double.valueOf(getData(mapLineClearRule.get(keyErrorXadtAir_Xadt)))>Double.valueOf(getData(mapLineClearRule.get(keyErrorXadtAir_Air)))?keyErrorXadtAir_Xadt:keyErrorXadtAir_Air;
       Double  dErrorXadtAir = Double.valueOf(getData(mapLineClearRule.get(keyErrorXadtAir)));
       
       //二、----------------清分金额----西安地铁故障 与14  西安地铁清分金额--划账单独计算
       BigDecimal sum_xadterror_14_xadtclear = new BigDecimal("0"); 
     
       //2.西安地铁故障--地铁与机场--机场线待清分合计
       BigDecimal sum_xadterror_14_airclear = new BigDecimal("0"); 
       //负数
       //与机场清分金额（后台存储，前台不显示） 合计值
       sum_xadterror_14_xadtclear = decimal.subtract(sum_xadterror_all_14).multiply(new BigDecimal(String.valueOf(dErrorXadtAir))).divide(decimal100).setScale(5,BigDecimal.ROUND_HALF_UP);
       sum_xadterror_14_airclear = decimal.subtract(sum_xadterror_all_14.add(sum_xadterror_14_xadtclear));//西安地铁内部故障--机场线清分结果
       
       //3.西安地铁故障--地铁与9号线
       //1.西安地铁故障--地铁与9号线--西安地铁待清分金额合计
       String  keyErrorXadtXazt_Xadt = SwCkClearRuleConstans.CLEAR_RULE_RETURN_ERROR+","+"2"+","+SwCkClearRuleConstans.SERVICE_ID_XADT;//到运营商级即可
       String  keyErrorXadtXazt_Xazt = SwCkClearRuleConstans.CLEAR_RULE_RETURN_ERROR+","+"2"+","+SwCkClearRuleConstans.SERVICE_ID_XAZT;//到运营商级即可
       
       //谁大取谁
       String keyErrorXadtXazt = Double.valueOf(getData(mapLineClearRule.get(keyErrorXadtXazt_Xadt)))>Double.valueOf(getData(mapLineClearRule.get(keyErrorXadtXazt_Xazt)))?keyErrorXadtXazt_Xadt:keyErrorXadtXazt_Xazt;
       Double  dErrorXadtXazt = Double.valueOf(getData(mapLineClearRule.get(keyErrorXadtXazt)));
       
      //西安地铁故障--地铁与9号线--9号线待清分合计
       BigDecimal sum_xadterror_9_xadtclear = new BigDecimal("0"); 
       BigDecimal sum_xadterror_9_xaztclear = new BigDecimal("0"); 
       //负数
       //与9号线清分金额（后台存储，前台不显示） 合计值
       sum_xadterror_9_xadtclear = decimal.subtract(sum_xadterror_all_9).multiply(new BigDecimal(String.valueOf(dErrorXadtXazt))).divide(decimal100).setScale(5,BigDecimal.ROUND_HALF_UP);
       sum_xadterror_9_xaztclear = decimal.subtract(sum_xadterror_all_9.add(sum_xadterror_9_xadtclear));//西安地铁内部故障--9号线清分结果     
       
       LOGGER.info(dErrorXadtXazt+"西安地铁故障  总的清分后金额==西安地铁=="+sum_xadterror_14_xadtclear+"=机场=="+sum_xadterror_14_airclear+"====9号线======="+sum_xadterror_9_xadtclear+"------"+sum_xadterror_9_xaztclear);

       //---------------------机场线故障导致退款----------------------------------
       //1.机场线故障导致的退款 西安地铁录入+机场导入
       BigDecimal sum_airerror_all_14 = new BigDecimal("0"); 
       sum_airerror_all_14 = sumC1_E14_XADT.add(sumC2_1);
       
       Double dError14 = Double.valueOf(getData(mapLineClearRule.get(keyErrorXadtAir_Air)));
       //2.   14号线故障--地铁与机场--地铁线路待清分合计
       BigDecimal sum_airerror_14_xadtclear = new BigDecimal("0");        
       //2.   14号线故障--地铁与机场--机场线待清分合计
       BigDecimal sum_airerror_14_airclear = new BigDecimal("0"); 
       //负数
       //（后台存储，前台不显示）
       sum_airerror_14_xadtclear = decimal.subtract(sum_airerror_all_14).multiply(new BigDecimal(String.valueOf(dError14))).divide(decimal100).setScale(5,BigDecimal.ROUND_HALF_UP);
       sum_airerror_14_airclear =  decimal.subtract(sum_airerror_all_14.add(sum_airerror_14_xadtclear));//14故障--机场线清分结果
       //0-(36000+(-3600))
	   //10.0机场故障  总的清分后金额==西安地铁==360000.00=地铁清分==-36000.00000====机场清分=======-396000.00000
	   LOGGER.info(dError14+"机场故障  总的清分后金额==西安地铁=="+sum_airerror_all_14+"=地铁清分=="+sum_airerror_14_xadtclear+"====机场清分======="+sum_airerror_14_airclear);
       //---------------------9号线故障导致退款----------------------------------       
       //2.9号线故障导致的退款 西安地铁录入+9号线导入
       BigDecimal sum_xazterror_all_9 = new BigDecimal("0"); 
       sum_xazterror_all_9 = sumC1_E9_XADT.add(sumC4_1);
       
       Double dError9 = Double.valueOf(getData(mapLineClearRule.get(keyErrorXadtXazt_Xazt)));
       //2.   9号线故障--地铁与中铁--地铁线路待清分合计
       BigDecimal sum_xazterror_9_xadtclear = new BigDecimal("0");        
       //2.   9号线故障--地铁与中铁--9号线待清分合计
       BigDecimal sum_xazterror_9_xaztclear = new BigDecimal("0"); 
       //负数
       //（后台存储，前台不显示）
       sum_xazterror_9_xadtclear = decimal.subtract(sum_xazterror_all_9).multiply(new BigDecimal(String.valueOf(dError9))).divide(decimal100).setScale(5,BigDecimal.ROUND_HALF_UP);
       sum_xazterror_9_xaztclear = decimal.subtract(sum_xazterror_all_9.add(sum_xazterror_9_xadtclear));//9故障--9号线清分结果
	    //0-(150000+(-30000))
       //20.09故障  总的清分后金额==西安地铁==150000.00=地铁清分==-30000.00000====9清分=======-180000.00000
	    LOGGER.info(dError9+"9故障  总的清分后金额==西安地铁=="+sum_xazterror_all_9+"=地铁清分=="+sum_xazterror_9_xadtclear+"====9清分======="+sum_xazterror_9_xaztclear);
       //--------------------9号线故障退款结束
       
       

        if (listLine != null && !listLine.isEmpty()) {
        	 PigxUser user = SecurityUtils.getUser();
        	 for (Map<String,String> lineMap : listLine) {
                 String lineCode = lineMap.get("lineCode");
 				 String serviceId = lineMap.get("operators");
                 String operatorsName = lineMap.get("operatorsName"); 
                 
                 SwCkClearEmergencyReturnticket swCkClearOtherAccount = new SwCkClearEmergencyReturnticket();
                 swCkClearOtherAccount.setBeginTime(LocalDate.parse(startDate,  DateTimeFormatter.ofPattern("yyyy-MM-dd")));
                 swCkClearOtherAccount.setEndTime(LocalDate.parse(endDate,  DateTimeFormatter.ofPattern("yyyy-MM-dd")));
                 swCkClearOtherAccount.setLineCode(lineCode);
                 swCkClearOtherAccount.setOperators(serviceId);
                 //TODO  根据日期范围+运营商ID+线路编号判断是否存在，如果存在更新，不存在插入
                 QueryWrapper<SwCkClearEmergencyReturnticket> query = Wrappers.query(swCkClearOtherAccount);
                 SwCkClearEmergencyReturnticket account = this.getOne(query);
                 if(ObjectUtil.isNotEmpty(account)){
                     swCkClearOtherAccount.setId(account.getId());
                     swCkClearOtherAccount.setUpdateTime(LocalDateTime.now());
                 }
                 swCkClearOtherAccount.setDeptId(user.getDeptId());
                 swCkClearOtherAccount.setCreatorId(user.getId());
                 swCkClearOtherAccount.setCreatorName(user.getNikeName());
                 swCkClearOtherAccount.setDelFlag("0");
                 

                 swCkClearOtherAccount.setEmeRecycle(decimal);//误出站回收
                 swCkClearOtherAccount.setEmeSale(decimal);//误出站发售
                 swCkClearOtherAccount.setEmeClear(decimal);//误出站清分
                 swCkClearOtherAccount.setFailNormalAirStationSale(decimal); //正常情况下退票（与14号线机场段） 退北客站北广场
                 swCkClearOtherAccount.setFailNormalAirStationClear(decimal);
                 swCkClearOtherAccount.setFailNormalAirOtherstationSale(decimal);//正常情况下退票（与14号线机场段） 退其他车站
                 swCkClearOtherAccount.setFailNormalAirOtherstationClear(decimal);
                 swCkClearOtherAccount.setFailNormalXaztStationSale(decimal);//正常情况下退票（与9号线机场段） 退纺织城
                 swCkClearOtherAccount.setFailNormalXaztStationClear(decimal);
                 swCkClearOtherAccount.setFailNormalXaztOtherstationSale(decimal);//正常情况下退票（与9号线机场段） 退其他车站
                 swCkClearOtherAccount.setFailNormalXaztOtherstationClear(decimal);
                 swCkClearOtherAccount.setFailSpeAirerrorSale(decimal);//故障退款 14号线机场段故障导致特殊退款
                 swCkClearOtherAccount.setFailSpeAirerrorClear(decimal);
                 swCkClearOtherAccount.setFailSpeXadterrorSale(decimal);//故障退款 西安地铁内部故障导致特殊退款 退14号线
                 swCkClearOtherAccount.setFailSpeXadterrorSaleNine(decimal);//故障退款 西安地铁内部故障导致特殊退款  退9号线
                 swCkClearOtherAccount.setFailSpeXadterrorClear(decimal);
                 swCkClearOtherAccount.setFailSpeXadterrorClearNine(decimal);
                 swCkClearOtherAccount.setFailSpeXadterrorClearSum(decimal);
                 swCkClearOtherAccount.setFailSpeXazterrorSale(decimal); //故障退款9号线故障导致特殊退款
                 swCkClearOtherAccount.setFailSpeXazterrorClear(decimal);
                 
                 swCkClearOtherAccount.setStreamXadtXadtRecycle(decimal);
                 swCkClearOtherAccount.setStreamXadtXadtSale(decimal);
                 swCkClearOtherAccount.setStreamXadtXadtClear(decimal);
                 swCkClearOtherAccount.setStreamXadtAirRecycle(decimal);
                 swCkClearOtherAccount.setStreamXadtAirClear(decimal);
                 swCkClearOtherAccount.setStreamXadtXaztRecycle(decimal);
                 swCkClearOtherAccount.setStreamXadtXaztClear(decimal);
                 swCkClearOtherAccount.setStreamXadtXaztRecycle(decimal);
                 swCkClearOtherAccount.setStreamXadtXaztClear(decimal);
                 swCkClearOtherAccount.setStreamAirXadtRecycle(decimal);
                 swCkClearOtherAccount.setStreamAirXadtSale(decimal);
                 swCkClearOtherAccount.setStreamAirXadtClear(decimal);
                 swCkClearOtherAccount.setStreamAirXixianRecycle(decimal);
                 swCkClearOtherAccount.setStreamAirXixianClear(decimal);
                 swCkClearOtherAccount.setStreamXaztXadtRecycle(decimal);
                 swCkClearOtherAccount.setStreamXaztXadtSale(decimal);
                 swCkClearOtherAccount.setStreamXaztXadtClear(decimal);
                 swCkClearOtherAccount.setStreamXaztXixianRecycle(decimal);
                 swCkClearOtherAccount.setStreamXaztXixianClear(decimal);
                 
                 
                 if(serviceId.equals(SwCkClearRuleConstans.SERVICE_ID_XADT)){  
                  //1. 应急纸票误出站（只有西安地铁和机场城际涉及）                  	 
                  swCkClearOtherAccount.setEmeRecycle(getLongByLineCode(lineCode,mapA1_1));//录入的回收机场城际的误出站
                  if(!lineCode.equals("4")){
                	  swCkClearOtherAccount.setEmeSale(decimal.subtract(getLongByLineCode(lineCode,mapA1_2)));//非4号线录入的西安地铁自己发售的应急纸票
                  }else{
                	  swCkClearOtherAccount.setEmeSale(decimal.subtract(sumA2_1.subtract(getLongByLineCode("2",mapA1_2)))); //去掉2号线的发售
                  }
                  swCkClearOtherAccount.setEmeClear(swCkClearOtherAccount.getEmeRecycle().add(swCkClearOtherAccount.getEmeSale()));
                  
                  //2.正常情况退票
                  //2.1  正常情况退票 西安地铁与机场城际
                  swCkClearOtherAccount.setFailNormalAirStationSale(decimal.subtract(getLongByLineCode(lineCode,mapB1_1)));//西安地铁线路退北客站北广场购买车票金额
                  swCkClearOtherAccount.setFailNormalAirOtherstationSale(decimal.subtract(getLongByLineCode(lineCode,mapB1_3)));//西安地铁线路退其他车站购买车票金额
                  if(lineCode.equals("4")){					 
					 String  keyNormalReturnXadtairAir = SwCkClearRuleConstans.CLEAR_RULE_RETURN_NORMAL+","+"1"+","+SwCkClearRuleConstans.SERVICE_ID_XADT;//到运营商级即可
                     Double  dNormalReturnXadtairAir = Double.valueOf(getData(mapLineClearRule.get(keyNormalReturnXadtairAir)));
                     //swCkClearOtherAccount.setFailNormalAirStationClear(Math.round(0-((0-(sumB1_1+sumB2_1))*dNormalReturnXadtairAir/100-(0-sumB2_1))));----TODO  没除以100
					// swCkClearOtherAccount.setFailNormalAirStationClear(((decimal.subtract((decimal.subtract((sumB1_1.add(sumB2_1)))).multiply(new BigDecimal(String.valueOf(dNormalReturnXadtairAir))).subtract((decimal.subtract(sumB2_1))))).divide(decimal100)).setScale(scale5,BigDecimal.ROUND_HALF_UP));  //清分金额变负数
					 swCkClearOtherAccount.setFailNormalAirStationClear((decimal.subtract(sumB1_1).subtract(sumB2_1)).multiply(new BigDecimal(String.valueOf(dNormalReturnXadtairAir))).divide(decimal100).add(sumB1_1).setScale(5,BigDecimal.ROUND_HALF_UP));//清分金额变正数
					  swCkClearOtherAccount.setFailNormalAirOtherstationClear(decimal.subtract(sumB2_3)); //4号线赋值=0-B2-3，其他为0
                  }
                  //2.2正常情况退票 西安地铁与西安中铁 
                  swCkClearOtherAccount.setFailNormalXaztStationSale(decimal.subtract(getLongByLineCode(lineCode,mapB3_1)));//西安地铁线路退纺织城购买车票金额
                  swCkClearOtherAccount.setFailNormalXaztOtherstationSale(decimal.subtract(getLongByLineCode(lineCode,mapB3_3)));//西安地铁线路退其他车站购买车票金额
                  if(lineCode.equals("1")){               	  
					  
					  //1号线赋值(0-SUM（B3-1）-B4-1)*比例-SUM(B3-1) 总合计*比例-地铁合计，其他为0
	                  String  keyNormalReturnXadtxaztXazt= SwCkClearRuleConstans.CLEAR_RULE_RETURN_NORMAL+","+"2"+","+SwCkClearRuleConstans.SERVICE_ID_XADT;
	                  Double  dNormalReturnXadtxaztXazt = Double.valueOf(getData(mapLineClearRule.get(keyNormalReturnXadtxaztXazt)));					 
	                  // swCkClearOtherAccount.setFailNormalXaztStationClear(Math.round(0-((0-(sumB3_1+sumB4_1))*dNormalReturnXadtxaztXazt/100-(0-sumB4_1))));  //清分金额变负数
	                  swCkClearOtherAccount.setFailNormalXaztStationClear((decimal.subtract(sumB3_1).subtract(sumB4_1)).multiply(new BigDecimal(String.valueOf(dNormalReturnXadtxaztXazt))).divide(decimal100).add(sumB3_1).setScale(5,BigDecimal.ROUND_HALF_UP));//清分金额变正数
					  //swCkClearOtherAccount.setFailNormalXaztStationClear(((decimal.subtract((decimal.subtract((sumB3_1.add(sumB4_1)))).multiply(new BigDecimal(String.valueOf(dNormalReturnXadtxaztXazt))).subtract((decimal.subtract(sumB4_1))))).divide(decimal100)).setScale(scale5,BigDecimal.ROUND_HALF_UP));  //清分金额变负数
	                  swCkClearOtherAccount.setFailNormalXaztOtherstationClear(decimal.subtract(sumB4_3));//1号线赋值=0-B4-3，其他为0
                  }
                  //4.特殊情况退票  地铁线路退换金额置为0，清分金额分别为9和14导入的西安地铁故障的金额。同时按9号线清分到1号线，14清分到4号线
                  //4.1 西安地铁-机场
                  // 西安地铁-机场城际-西安地铁线路-机场城际故障退款金额
                 
                  swCkClearOtherAccount.setFailSpeXadterrorSale(decimal.subtract(getLongByLineCode(lineCode,mapC1_3)));
                  swCkClearOtherAccount.setFailSpeXadterrorSaleNine(decimal.subtract(getLongByLineCode(lineCode,mapC1_4)));
				  swCkClearOtherAccount.setFailSpeXadterrorClear(decimal);
				  swCkClearOtherAccount.setFailSpeXadterrorClearNine(decimal);
				  swCkClearOtherAccount.setFailSpeXadterrorClearSum(decimal);
				  swCkClearOtherAccount.setFailSpeAirerrorSale(decimal);
				  swCkClearOtherAccount.setFailSpeAirerrorClear(decimal);
				  swCkClearOtherAccount.setFailSpeXazterrorSale(decimal);
				  swCkClearOtherAccount.setFailSpeXazterrorClear(decimal);
				  
				  //-----------------------计算西安地铁内部故障--与机场线--各个线路的清分金额
				  String  key_xadterror_14_xadt = SwCkClearRuleConstans.CLEAR_RULE_RETURN_ERROR+","+"1"+","+SwCkClearRuleConstans.SERVICE_ID_XADT+","+lineCode;
                  Double  d_xadterror_14_xadt = Double.valueOf(getData(mapLineClearRule.get(key_xadterror_14_xadt)));
                  BigDecimal decimal_14_tmp = new BigDecimal("0");
                  decimal_14_tmp = (sum_xadterror_14_xadtclear.multiply(new BigDecimal(String.valueOf(d_xadterror_14_xadt))).divide(decimal100)).setScale(scale5,BigDecimal.ROUND_HALF_UP);
                  //清分金额-录入的14号线退款金额
                  swCkClearOtherAccount.setFailSpeXadterrorClear(decimal_14_tmp.subtract(swCkClearOtherAccount.getFailSpeXadterrorSale()));
                  if(lineCode.equals("1")){
                	  swCkClearOtherAccount.setFailSpeXadterrorClear(decimal_14_tmp.subtract(swCkClearOtherAccount.getFailSpeXadterrorSale()).add(getLongByLineCode("71",mapC1_3)));
                  }
                  if(lineCode.equals("5")){
                	  swCkClearOtherAccount.setFailSpeXadterrorClear(decimal_14_tmp.subtract(swCkClearOtherAccount.getFailSpeXadterrorSale()).add(getLongByLineCode("72",mapC1_3)));
                  }
				   LOGGER.info("各个线路清分金额==="+lineCode+"------------金额--------------"+decimal_14_tmp);
                  
                  //计算西安地铁内部故障--与9号线--各个线路的清分金额
				  String  key_xadterror_9_xadt = SwCkClearRuleConstans.CLEAR_RULE_RETURN_ERROR+","+"2"+","+SwCkClearRuleConstans.SERVICE_ID_XADT+","+lineCode;
                  Double  d_xadterror_9_xadt = Double.valueOf(getData(mapLineClearRule.get(key_xadterror_9_xadt)));
                  BigDecimal decimal_9_tmp = new BigDecimal("0");				 
                  decimal_9_tmp = (sum_xadterror_9_xadtclear.multiply(new BigDecimal(String.valueOf(d_xadterror_9_xadt))).divide(decimal100)).setScale(scale5,BigDecimal.ROUND_HALF_UP);
                  //清分金额-录入的9号线退款金额
                  swCkClearOtherAccount.setFailSpeXadterrorClearNine(decimal_9_tmp.subtract(swCkClearOtherAccount.getFailSpeXadterrorSaleNine()));
                  if(lineCode.equals("1")){
                	  swCkClearOtherAccount.setFailSpeXadterrorClearNine(decimal_9_tmp.subtract(swCkClearOtherAccount.getFailSpeXadterrorSaleNine()).add(getLongByLineCode("71",mapC1_4)));
                  }
                  if(lineCode.equals("5")){
                	  swCkClearOtherAccount.setFailSpeXadterrorClearNine(decimal_9_tmp.subtract(swCkClearOtherAccount.getFailSpeXadterrorSaleNine()).add(getLongByLineCode("72",mapC1_4)));
                  }
				   LOGGER.info("地铁内部与9号线 各个线路清分金额==="+lineCode+"------------金额----基数----"+sum_xadterror_9_xadtclear+"--比例-"+d_xadterror_9_xadt+"---"+decimal_9_tmp);
                  swCkClearOtherAccount.setFailSpeXadterrorClearSum(swCkClearOtherAccount.getFailSpeXadterrorClear().add(swCkClearOtherAccount.getFailSpeXadterrorClearNine()));
				  //----------------------------西安地铁内部的计算完毕-----------------------------------------------
				  //-----------------------------14号线机场故障退款---开始--------------------------
                  swCkClearOtherAccount.setFailSpeAirerrorSale(decimal.subtract(getLongByLineCode(lineCode,mapC1_E14_XADT)));//录入
                  BigDecimal decimal_14error_tmp = new BigDecimal("0");
                  decimal_14error_tmp = (sum_airerror_14_xadtclear.multiply(new BigDecimal(String.valueOf(d_xadterror_14_xadt))).divide(decimal100)).setScale(scale5,BigDecimal.ROUND_HALF_UP);
                  //清分金额-录入的14号线退款金额
                  swCkClearOtherAccount.setFailSpeAirerrorClear(decimal_14error_tmp.subtract(swCkClearOtherAccount.getFailSpeAirerrorSale()));
                  if(lineCode.equals("1")){
                	  swCkClearOtherAccount.setFailSpeAirerrorClear(decimal_14error_tmp.subtract(swCkClearOtherAccount.getFailSpeAirerrorSale()).add(getLongByLineCode("71",mapC1_E14_XADT)));
                  }
                  if(lineCode.equals("5")){
                	  swCkClearOtherAccount.setFailSpeAirerrorClear(decimal_14error_tmp.subtract(swCkClearOtherAccount.getFailSpeAirerrorSale()).add(getLongByLineCode("72",mapC1_E14_XADT)));
                  } 
                  //----------------------------9号线故障退款----------------------------------
                  swCkClearOtherAccount.setFailSpeXazterrorSale(decimal.subtract(getLongByLineCode(lineCode,mapC1_E9_XADT)));//录入                 
                  BigDecimal decimal_9error_tmp = new BigDecimal("0");
                  decimal_9error_tmp = (sum_xazterror_9_xadtclear.multiply(new BigDecimal(String.valueOf(d_xadterror_9_xadt))).divide(decimal100)).setScale(scale5,BigDecimal.ROUND_HALF_UP);
                  //清分金额-录入的9号线退款金额
                  swCkClearOtherAccount.setFailSpeXazterrorClear(decimal_9error_tmp.subtract(swCkClearOtherAccount.getFailSpeXazterrorSale()));
                  if(lineCode.equals("1")){
                	  swCkClearOtherAccount.setFailSpeXazterrorClear(decimal_9error_tmp.subtract(swCkClearOtherAccount.getFailSpeXazterrorSale()).add(getLongByLineCode("71",mapC1_E9_XADT)));
                  }
                  if(lineCode.equals("5")){
                	  swCkClearOtherAccount.setFailSpeXazterrorClear(decimal_9error_tmp.subtract(swCkClearOtherAccount.getFailSpeXazterrorSale()).add(getLongByLineCode("72",mapC1_E9_XADT)));
                  } 
                 
                  //3.---------------------------------------大客流----------------------------开始
                  //3.1 西安地铁-西咸
                  
                  //3.1.1 西安地铁大客流发售应急纸票且西安地铁回收  发售取配票与配备用金，分西咸和西安地铁，然后清分时分到西安地铁各线路
                  swCkClearOtherAccount.setStreamXadtXadtRecycle(getLongByLineCode(lineCode,mapD1_1));   
                  swCkClearOtherAccount.setStreamXadtXadtSale(getLongByListMap(lineCode,listXadtStationSale));//getLongByLineCode(lineCode,mapD1_6));   
                  String  keyD1_2 = SwCkClearRuleConstans.CLEAR_RULE_EMERGENCY_BIGSTREAM+","+"1"+","+SwCkClearRuleConstans.SERVICE_ID_XADT+","+lineCode;
                  Double  dD1_2 = Double.valueOf(getData(mapLineClearRule.get(keyD1_2)));
                  // 西安地铁内部回收 = 西安地铁发售-14号线机场段回收西安地铁-9号线回收西安地铁-
                  //swCkClearOtherAccount.setStreamXadtXadtClear(Math.round(getSingleLong(streamWaitSumXadtAndXian)*dD1_2/100));//待清分金额就是此值，也可以直接使用
                  BigDecimal lInnerClear = ((sumD1_6.subtract(sumD2_3).subtract(sumD4_3)).multiply(new BigDecimal(String.valueOf(dD1_2))).divide(decimal100).subtract(swCkClearOtherAccount.getStreamXadtXadtSale())).setScale(scale5,BigDecimal.ROUND_HALF_UP);
                  swCkClearOtherAccount.setStreamXadtXadtClear(lInnerClear); 
                
                  
                  //3.1.2西安地铁大客流发售应急纸票且机场回收
                  swCkClearOtherAccount.setStreamXadtAirRecycle(decimal);//地铁线路关于机场的回收设置为0
                  //机场的回收合计*西安地铁与机场城际的西安地铁运营商比例*西安地铁与机场城际的西安地铁线路比例   大客流的接口要支持到运营商                 
                  String keyD1_6 = SwCkClearRuleConstans.CLEAR_RULE_EMERGENCY_BIGSTREAM+","+"2"+","+SwCkClearRuleConstans.SERVICE_ID_XADT; 
                  String keyD1_6_1 = SwCkClearRuleConstans.CLEAR_RULE_EMERGENCY_BIGSTREAM+","+"2"+","+SwCkClearRuleConstans.SERVICE_ID_XADT+","+lineCode;
                  Double dD1_6 =  Double.valueOf("100");//Double.valueOf(getData(mapLineClearRule.get(keyD1_6)));   暂时按100%算  20210908
                  Double dD1_6_1 =  Double.valueOf(getData(mapLineClearRule.get(keyD1_6_1)));
                  swCkClearOtherAccount.setStreamXadtAirClear((sumD2_3.multiply(new BigDecimal(String.valueOf(dD1_6))).multiply(new BigDecimal(String.valueOf(dD1_6_1))).divide(decimal10000)).setScale(scale5,BigDecimal.ROUND_HALF_UP));//sumD1_6 原来用发售的计算
                  
                  //3.1.3 西安地铁大客流发售应急纸票且中铁回收
                  swCkClearOtherAccount.setStreamXadtXaztRecycle(decimal);//地铁线路关于西安中铁的回收设置为0
                  //西安中铁的回收合计*西安地铁与西安中铁的西安地铁运营商比例*西安地铁与西安中铁的西安地铁线路比例                    
                  String keyD1_7 = SwCkClearRuleConstans.CLEAR_RULE_EMERGENCY_BIGSTREAM+","+"4"+","+SwCkClearRuleConstans.SERVICE_ID_XADT; 
                  String keyD1_7_1 = SwCkClearRuleConstans.CLEAR_RULE_EMERGENCY_BIGSTREAM+","+"4"+","+SwCkClearRuleConstans.SERVICE_ID_XADT+","+lineCode;
                  Double dD1_7 =  Double.valueOf("100");//Double.valueOf(getData(mapLineClearRule.get(keyD1_7)));暂时100%算 20210908
                  Double dD1_7_1 =  Double.valueOf(getData(mapLineClearRule.get(keyD1_7_1)));
                  swCkClearOtherAccount.setStreamXadtXaztClear((sumD4_3.multiply(new BigDecimal(String.valueOf(dD1_7))).multiply(new BigDecimal(String.valueOf(dD1_7_1))).divide(decimal10000)).setScale(scale5,BigDecimal.ROUND_HALF_UP));
                  
				  
				  //3.1.4 14号线机场段发售大客流应急纸票且西安地铁回收

				  //暂时使用				 
				  Double dD11 =  Double.valueOf("100");//Double.valueOf(getData(mapLineClearRule.get(keyD1_6)));
                  Double dD11_1 =  Double.valueOf(getData(mapLineClearRule.get(keyD1_6_1)));
                  swCkClearOtherAccount.setStreamAirXadtSale(decimal);//发售设置为0
                  swCkClearOtherAccount.setStreamAirXadtRecycle(getLongByLineCode(lineCode,mapD14_16_1));//原来mapD2_1
                  //地铁回收14号线合计*西安地铁与机场城际的西安地铁运营商比例*西安地铁与机场城际的西安地铁线路比例
                  swCkClearOtherAccount.setStreamAirXadtClear((sumD14_16_1.multiply(new BigDecimal(String.valueOf(dD11))).multiply(new BigDecimal(String.valueOf(dD11_1))).divide(decimal10000)).setScale(scale5,BigDecimal.ROUND_HALF_UP));

                  //3.1.5 14号线机场段发售大客流应急纸票且西咸回收（西安地铁-机场-西咸三家清分）mapD3_3赋值到西咸线路即可
                  swCkClearOtherAccount.setStreamAirXixianRecycle(decimal);//非西咸车站回收金额设置为0
                  //西咸回收14号线金额合计*西安地铁、西咸、机场城际三家的西安地铁运营商比例*西安地铁中的线路比例
                  String keyD3_3 = SwCkClearRuleConstans.CLEAR_RULE_EMERGENCY_BIGSTREAM+","+"3"+","+SwCkClearRuleConstans.SERVICE_ID_XADT;
                  String keyD3_3_1 = SwCkClearRuleConstans.CLEAR_RULE_EMERGENCY_BIGSTREAM+","+"3"+","+SwCkClearRuleConstans.SERVICE_ID_XADT+","+lineCode;
                  Double dD3_3 =  Double.valueOf("100");//Double.valueOf(getData(mapLineClearRule.get(keyD3_3)));
                  Double dD3_3_1 =  Double.valueOf(getData(mapLineClearRule.get(keyD3_3_1)));
                  swCkClearOtherAccount.setStreamAirXixianClear((sumD3_3.multiply(new BigDecimal(String.valueOf(dD3_3))).multiply(new BigDecimal(String.valueOf(dD3_3_1))).divide(decimal10000)).setScale(scale5,BigDecimal.ROUND_HALF_UP));

                  //3.1.6 9号线大客流发售应急纸票且西安地铁回收
                  swCkClearOtherAccount.setStreamXaztXadtSale(decimal);//发售设置为0
                  swCkClearOtherAccount.setStreamXaztXadtRecycle(getLongByLineCode(lineCode,mapD9_16_1));//原来mapD1_3
                  //地铁回收9号线合计*西安地铁与西安中铁的西安地铁运营商比例*西安地铁与西安中铁的西安地铁线路比例
                  swCkClearOtherAccount.setStreamXaztXadtClear((sumD9_16_1.multiply(new BigDecimal(String.valueOf(dD1_7))).multiply(new BigDecimal(String.valueOf(dD1_7_1))).divide(decimal10000)).setScale(scale5,BigDecimal.ROUND_HALF_UP));

                  //3.1.7 9号线大客流发售应急纸票且西咸回收（西安地铁-中铁-西咸三家清分）
                  swCkClearOtherAccount.setStreamXaztXixianRecycle(decimal);//非西咸车站回收金额设置为0 mapD5_7设置到西咸线路
                  //西咸回收9号线金额合计*西安地铁、西咸、西安中铁三家的西安地铁运营商比例*西安地铁中的线路比例
                  String keyD5_7 = SwCkClearRuleConstans.CLEAR_RULE_EMERGENCY_BIGSTREAM+","+"5"+","+SwCkClearRuleConstans.SERVICE_ID_XADT;
                  String keyD5_7_1 = SwCkClearRuleConstans.CLEAR_RULE_EMERGENCY_BIGSTREAM+","+"5"+","+SwCkClearRuleConstans.SERVICE_ID_XADT+","+lineCode;
                  Double dD5_7 =  Double.valueOf("100");//Double.valueOf(getData(mapLineClearRule.get(keyD5_7)));
                  Double dD5_7_1 =  Double.valueOf(getData(mapLineClearRule.get(keyD5_7_1)));
                  swCkClearOtherAccount.setStreamXaztXixianClear((sumD5_3.multiply(new BigDecimal(String.valueOf(dD5_7))).multiply(new BigDecimal(String.valueOf(dD5_7_1))).divide(decimal10000)).setScale(scale5,BigDecimal.ROUND_HALF_UP));
                  //----------------------大客流----------------------------结束
                 
                	 
                 }else if(serviceId.equals(SwCkClearRuleConstans.SERVICE_ID_XIXIAN)){ 
                	//3.----------------------大客流----------------------------开始
                	 //3.1.1 西安地铁大客流发售应急纸票且西安地铁回收  发售取配票与配备用金，分西咸和西安地铁，然后清分时分到西安地铁各线路
                     swCkClearOtherAccount.setStreamXadtXadtRecycle(decimal);  //回收设置为0
					 swCkClearOtherAccount.setStreamXadtXadtSale(getLongByListMap(lineCode,listXadtStationSale));//getLongByLineCode(lineCode,mapD1_9));
                     swCkClearOtherAccount.setStreamXadtXadtClear(decimal);//清分设置为0
                     
                     //3.1.2西安地铁大客流发售应急纸票且机场回收
                     swCkClearOtherAccount.setStreamXadtAirRecycle(decimal);
                     swCkClearOtherAccount.setStreamXadtAirClear(decimal);
                     
                     //3.1.3 西安地铁大客流发售应急纸票且中铁回收
                     swCkClearOtherAccount.setStreamXadtXaztRecycle(decimal);//地铁线路关于西安中铁的回收设置为0
                     swCkClearOtherAccount.setStreamXadtXaztClear(decimal);
                     
                     //3.1.4 14号线机场段发售大客流应急纸票且西安地铁回收--西咸和机场没关系
                     swCkClearOtherAccount.setStreamAirXadtSale(decimal);//发售设置为0
                     swCkClearOtherAccount.setStreamAirXadtRecycle(decimal);
                     swCkClearOtherAccount.setStreamAirXadtClear(decimal);
                     
                     //3.1.5 14号线机场段发售大客流应急纸票且西咸回收（西安地铁-机场-西咸三家清分）mapD3_3赋值到西咸线路即可
                     swCkClearOtherAccount.setStreamAirXixianRecycle(getLongByLineCode(lineCode,mapD3_3));//非西咸车站回收金额设置为0 
                     //西咸回收14号线金额合计*西安地铁、西咸、机场城际三家的西咸运营商比例*西咸中的线路比例
                     String keyD3_3 = SwCkClearRuleConstans.CLEAR_RULE_EMERGENCY_BIGSTREAM+","+"3"+","+SwCkClearRuleConstans.SERVICE_ID_XIXIAN;
                     String keyD3_3_1 = SwCkClearRuleConstans.CLEAR_RULE_EMERGENCY_BIGSTREAM+","+"3"+","+SwCkClearRuleConstans.SERVICE_ID_XIXIAN+","+lineCode;
                     Double dD3_3 =  Double.valueOf("100");//Double.valueOf(getData(mapLineClearRule.get(keyD3_3)));
                     Double dD3_3_1 =  Double.valueOf(getData(mapLineClearRule.get(keyD3_3_1)));
                     //LOGGER.info("sumD3_3===="+sumD3_3+" bili===="+dD3_3_1);
					 swCkClearOtherAccount.setStreamAirXixianClear((sumD3_3.multiply(new BigDecimal(String.valueOf(dD3_3))).multiply(new BigDecimal(String.valueOf(dD3_3_1))).divide(decimal10000)).setScale(scale5,BigDecimal.ROUND_HALF_UP));

                     //3.1.6 9号线大客流发售应急纸票且西安地铁回收
                     swCkClearOtherAccount.setStreamXaztXadtSale(decimal);//发售设置为0
                     swCkClearOtherAccount.setStreamXaztXadtRecycle(decimal);
                     swCkClearOtherAccount.setStreamXaztXadtClear(decimal);
                     
                     //3.1.7 9号线大客流发售应急纸票且西咸回收（西安地铁-中铁-西咸三家清分）
                     swCkClearOtherAccount.setStreamXaztXixianRecycle(getLongByLineCode(lineCode,mapD5_3));//非西咸车站回收金额设置为0 mapD5_7设置到西咸线路
                     //西咸回收9号线金额合计*西安地铁、西咸、西安中铁三家的西咸运营商比例*西咸线路中的线路比例
                     String keyD5_7 = SwCkClearRuleConstans.CLEAR_RULE_EMERGENCY_BIGSTREAM+","+"5"+","+SwCkClearRuleConstans.SERVICE_ID_XIXIAN;
                     String keyD5_7_1 = SwCkClearRuleConstans.CLEAR_RULE_EMERGENCY_BIGSTREAM+","+"5"+","+SwCkClearRuleConstans.SERVICE_ID_XIXIAN+","+lineCode;
                     Double dD5_7 =    Double.valueOf("100");//Double.valueOf(getData(mapLineClearRule.get(keyD5_7)));
                     Double dD5_7_1 = Double.valueOf(getData(mapLineClearRule.get(keyD5_7_1)));
                     swCkClearOtherAccount.setStreamXaztXixianClear((sumD5_3.multiply(new BigDecimal(String.valueOf(dD5_7))).multiply(new BigDecimal(String.valueOf(dD5_7_1))).divide(decimal10000)).setScale(scale5,BigDecimal.ROUND_HALF_UP));

                     //----------------------大客流----------------------------结束
                     
                     //特殊退款
                     swCkClearOtherAccount.setFailSpeXadterrorSale(decimal.subtract(getLongByLineCode(lineCode,mapC1_3)));
                     swCkClearOtherAccount.setFailSpeXadterrorSaleNine(decimal.subtract(getLongByLineCode(lineCode,mapC1_4))); 
                     swCkClearOtherAccount.setFailSpeAirerrorSale(decimal.subtract(getLongByLineCode(lineCode,mapC1_E14_XADT)));
                     swCkClearOtherAccount.setFailSpeXazterrorSale(decimal.subtract(getLongByLineCode(lineCode,mapC1_E9_XADT))); 
                     
                	 
                 }else if(serviceId.equals(SwCkClearRuleConstans.SERVICE_ID_AIR)){  
                	 //1. 应急纸票误出站（只有西安地铁和机场城际涉及）         
                	 swCkClearOtherAccount.setEmeRecycle(sumA2_1);
                	 swCkClearOtherAccount.setEmeSale(decimal.subtract(sumA1_1));
                	 swCkClearOtherAccount.setEmeClear(swCkClearOtherAccount.getEmeRecycle().add(swCkClearOtherAccount.getEmeSale()));
                	//2.正常情况退票
                	 swCkClearOtherAccount.setFailNormalAirStationSale(decimal.subtract(sumB2_1));
                	 //String  keyNormalReturnXadtairAir = SwCkClearRuleConstans.CLEAR_RULE_RETURN_NORMAL+","+"1"+","+SwCkClearRuleConstans.SERVICE_ID_AIR+","+SwCkClearRuleConstans.LINE_ID_AIR_14;
					 String  keyNormalReturnXadtairAir = SwCkClearRuleConstans.CLEAR_RULE_RETURN_NORMAL+","+"1"+","+SwCkClearRuleConstans.SERVICE_ID_AIR;//到运营商级即可
                     Double  dNormalReturnXadtairAir = Double.valueOf(getData(mapLineClearRule.get(keyNormalReturnXadtairAir)));
                     //-30(地铁+机场合计)*比例+机场合计  (0-sumB1_1-sumB2_1)*dNormalReturnXadtairAir/100-(0-sumB2_1)             ((decimal.subtract(sumB1_1).substract(sumB2_1)).multiply(new BigDecimal(String.valueOf(dNormalReturnXadtairAir))).divide(decimal100).substract(sumB1_1)).setScale(scale5,BigDecimal.ROUND_HALF_UP)
                     //swCkClearOtherAccount.setFailNormalAirStationClear(Math.round(0-((0-sumB1_1-sumB2_1)*dNormalReturnXadtairAir/100-(0-sumB2_1))));  //清分金额变正数                    
					               	
					 swCkClearOtherAccount.setFailNormalAirStationClear((decimal.subtract(sumB1_1).subtract(sumB2_1)).multiply(new BigDecimal(String.valueOf(dNormalReturnXadtairAir))).divide(decimal100).add(sumB2_1).setScale(5,BigDecimal.ROUND_HALF_UP));//清分金额变正数
					 swCkClearOtherAccount.setFailNormalAirOtherstationSale(decimal.subtract(sumB2_3));

                	 swCkClearOtherAccount.setFailNormalAirOtherstationClear(sumB2_3);
                	 
                	 //4.特殊情况退票
                     //4.1 西安地铁-机场
                	 swCkClearOtherAccount.setFailSpeXadterrorSale(decimal.subtract(sumC2_3));//
                	 swCkClearOtherAccount.setFailSpeXadterrorClear(sum_xadterror_14_airclear.subtract(swCkClearOtherAccount.getFailSpeXadterrorSale()));//
                	 swCkClearOtherAccount.setFailSpeXadterrorClearSum(swCkClearOtherAccount.getFailSpeXadterrorClear());
                	 
                	 swCkClearOtherAccount.setFailSpeAirerrorSale(decimal.subtract(sumC2_1));//导入
                	 swCkClearOtherAccount.setFailSpeAirerrorClear(sum_airerror_14_airclear.subtract(swCkClearOtherAccount.getFailSpeAirerrorSale()));//
                     
                     //3.大客流所有都涉及
                     //3.1.1 西安地铁大客流发售应急纸票且西安地铁回收  
                     swCkClearOtherAccount.setStreamXadtXadtRecycle(decimal); //
                     swCkClearOtherAccount.setStreamXadtXadtSale(decimal);
                     swCkClearOtherAccount.setStreamXadtXadtClear(decimal);
                     
                     //3.1.2西安地铁大客流发售应急纸票且机场回收
                     swCkClearOtherAccount.setStreamXadtAirRecycle(sumD2_3);
                     //机场的回收合计*西安地铁与机场城际的机场城际运营商比例*西安地铁与机场城际的机场城际线路比例                    
                     String keyD1_6 = SwCkClearRuleConstans.CLEAR_RULE_EMERGENCY_BIGSTREAM+","+"2"+","+SwCkClearRuleConstans.SERVICE_ID_AIR;                    
                     Double dD1_6 =  Double.valueOf(getData(mapLineClearRule.get(keyD1_6)));
                     swCkClearOtherAccount.setStreamXadtAirClear((sumD2_3.multiply(new BigDecimal(String.valueOf(dD1_6))).divide(decimal100)).setScale(scale5,BigDecimal.ROUND_HALF_UP));

                     //3.1.3 西安地铁大客流发售应急纸票且中铁回收
                     swCkClearOtherAccount.setStreamXadtXaztRecycle(decimal);//地铁线路关于西安中铁的回收设置为0
                     swCkClearOtherAccount.setStreamXadtXaztClear(decimal);
                     
                     //3.1.4 14号线机场段发售大客流应急纸票且西安地铁回收
                     swCkClearOtherAccount.setStreamAirXadtSale(sumD14_3); //导入发售金额 原来sumD2_3                
                     swCkClearOtherAccount.setStreamAirXadtRecycle(sumD14_3.subtract(sumD14_16_1).subtract(sumD5_3));//导入的发售金额-西安地铁售卖14号线发售的合计-西咸回收14号线机场线
                     //地铁回收14号线合计*西安地铁与机场城际的机场城际运营商比例
					 // 西地铁回收14号线的合计*比例+XadtRecycle-sumD14_3
					 //sumD14_16_1*比例+sumD14_16_1+sumD5_3  化简后
                     //(sumD14_16_1.multiply(new BigDecimal(String.valueOf(dD1_6))).divide(decimal100).add(sumD14_16_1).add(sumD5_3)).setScale(scale5,BigDecimal.ROUND_HALF_UP)
                    
                     //swCkClearOtherAccount.setStreamAirXadtClear((sumD2_1.multiply(new BigDecimal(String.valueOf(dD1_6))).divide(decimal100)).setScale(scale5,BigDecimal.ROUND_HALF_UP));
                     //LOGGER.info("sumD14_16_1====="+sumD14_16_1+"swCkClearOtherAccount.setStreamAirXadtRecycle()===="+swCkClearOtherAccount.getStreamAirXadtRecycle()+"--dD1_6=="+dD1_6+"sumD14_3==="+sumD14_3);
					 swCkClearOtherAccount.setStreamAirXadtClear((sumD14_16_1.multiply(new BigDecimal(String.valueOf(dD1_6)))).divide(decimal100).add(swCkClearOtherAccount.getStreamAirXadtRecycle()).subtract(sumD14_3).setScale(scale5,BigDecimal.ROUND_HALF_UP));
                    
					 //3.1.5 14号线机场段发售大客流应急纸票且西咸回收（西安地铁-机场-西咸三家清分）
                     swCkClearOtherAccount.setStreamAirXixianRecycle(decimal);
                     //西咸回收14号线金额合计*西安地铁、西咸、机场城际三家的西咸运营商比例*西咸中的线路比例
                     String keyD3_3 = SwCkClearRuleConstans.CLEAR_RULE_EMERGENCY_BIGSTREAM+","+"3"+","+SwCkClearRuleConstans.SERVICE_ID_AIR;                    
                     Double dD3_3 =  Double.valueOf(getData(mapLineClearRule.get(keyD3_3)));
                     swCkClearOtherAccount.setStreamAirXixianClear((sumD3_3.multiply(new BigDecimal(String.valueOf(dD3_3))).divide(decimal100)).setScale(scale5,BigDecimal.ROUND_HALF_UP));

                     //3.1.6 9号线大客流发售应急纸票且西安地铁回收
                     swCkClearOtherAccount.setStreamXaztXadtSale(decimal);//发售设置为0
                     swCkClearOtherAccount.setStreamXaztXadtRecycle(decimal);
                     swCkClearOtherAccount.setStreamXaztXadtClear(decimal);
                     
                     //3.1.7 9号线大客流发售应急纸票且西咸回收（西安地铁-中铁-西咸三家清分）
                     swCkClearOtherAccount.setStreamXaztXixianRecycle(decimal);
                     swCkClearOtherAccount.setStreamXaztXixianClear(decimal);
                	 
                 }else if(serviceId.equals(SwCkClearRuleConstans.SERVICE_ID_XAZT)){ 
                	//2.正常情况退票                	
                	 swCkClearOtherAccount.setFailNormalXaztStationSale(decimal.subtract(sumB4_1));
                	 String  keyNormalReturnXadtxaztXazt= SwCkClearRuleConstans.CLEAR_RULE_RETURN_NORMAL+","+"2"+","+SwCkClearRuleConstans.SERVICE_ID_XAZT;
	                 Double  dNormalReturnXadtxaztXazt = Double.valueOf(getData(mapLineClearRule.get(keyNormalReturnXadtxaztXazt)));
	                 //swCkClearOtherAccount.setFailNormalXaztStationClear(Math.round((0-(sumB3_1+sumB4_1))*dNormalReturnXadtxaztXazt/100-(0-sumB4_1)));  //清分金额变正数		
					 //swCkClearOtherAccount.setFailNormalXaztStationClear(((decimal.subtract((decimal.subtract((sumB3_1.add(sumB4_1)))).multiply(new BigDecimal(String.valueOf(dNormalReturnXadtxaztXazt))).subtract((decimal.subtract(sumB4_1))))).divide(decimal100)).setScale(scale5,BigDecimal.ROUND_HALF_UP));  //清分金额变正数
                	 swCkClearOtherAccount.setFailNormalXaztStationClear((decimal.subtract(sumB3_1).subtract(sumB4_1)).multiply(new BigDecimal(String.valueOf(dNormalReturnXadtxaztXazt))).divide(decimal100).add(sumB4_1).setScale(5,BigDecimal.ROUND_HALF_UP));//清分金额变正数
					 swCkClearOtherAccount.setFailNormalXaztOtherstationSale(decimal.subtract(sumB4_3));
                	 swCkClearOtherAccount.setFailNormalXaztOtherstationClear(sumB4_3);
				
                	 
                	 //4.特殊情况退票 到运营商级别
                     //4.2 西安地铁内部-与14号线
                	 swCkClearOtherAccount.setFailSpeXadterrorSaleNine(decimal.subtract(sumC4_3));//
                	 swCkClearOtherAccount.setFailSpeXadterrorClearNine(sum_xadterror_9_xaztclear.subtract(swCkClearOtherAccount.getFailSpeXadterrorSaleNine()));//
                	 swCkClearOtherAccount.setFailSpeXadterrorClearSum(swCkClearOtherAccount.getFailSpeXadterrorClearNine());
                	 //西安地铁-西安中铁
                	 swCkClearOtherAccount.setFailSpeXazterrorSale(decimal.subtract(sumC4_1));//导入
                	 swCkClearOtherAccount.setFailSpeXazterrorClear(sum_xazterror_9_xaztclear.subtract(swCkClearOtherAccount.getFailSpeXazterrorSale()));
                    //-----------------------------特殊退款完成--------------------------------------------
                	 
                	 //3.大客流
                     //3.1.1 西安地铁大客流发售应急纸票且西安地铁回收  
                     swCkClearOtherAccount.setStreamXadtXadtRecycle(decimal);   //sumD4_3
                     swCkClearOtherAccount.setStreamXadtXadtSale(decimal);
                     swCkClearOtherAccount.setStreamXadtXadtClear(decimal);
                     
                     //3.1.2西安地铁大客流发售应急纸票且机场回收
                     swCkClearOtherAccount.setStreamXadtAirRecycle(decimal);
                     swCkClearOtherAccount.setStreamXadtAirClear(decimal);
                     
                     //3.1.3 西安地铁大客流发售应急纸票且中铁回收
                     swCkClearOtherAccount.setStreamXadtXaztRecycle(sumD4_3);
                     //西安中铁的回收合计*西安地铁与西安中铁的西安地铁运营商比例*西安地铁与西安中铁的西安中铁线路比例                    
                     String keyD1_7 = SwCkClearRuleConstans.CLEAR_RULE_EMERGENCY_BIGSTREAM+","+"4"+","+SwCkClearRuleConstans.SERVICE_ID_XAZT;                   
                     Double dD1_7 =  Double.valueOf(getData(mapLineClearRule.get(keyD1_7)));
                     swCkClearOtherAccount.setStreamXadtXaztClear((sumD4_3.multiply(new BigDecimal(String.valueOf(dD1_7))).divide(decimal100)).setScale(scale5,BigDecimal.ROUND_HALF_UP));
                    //3.1.4 14号线机场段发售大客流应急纸票且西安地铁回收
                     swCkClearOtherAccount.setStreamAirXadtSale(decimal);
                     swCkClearOtherAccount.setStreamAirXadtRecycle(decimal);
                     swCkClearOtherAccount.setStreamAirXadtClear(decimal);

                     //3.1.5 14号线机场段发售大客流应急纸票且西咸回收（西安地铁-机场-西咸三家清分）
                     swCkClearOtherAccount.setStreamAirXixianRecycle(decimal);
                     swCkClearOtherAccount.setStreamAirXixianClear(decimal);
                     
                     //3.1.6 9号线大客流发售应急纸票且西安地铁回收
                     swCkClearOtherAccount.setStreamXaztXadtSale(sumD9_3);//导入的发售
                     swCkClearOtherAccount.setStreamXaztXadtRecycle(sumD9_3.subtract(sumD9_16_1).subtract(sumD5_3));//导入的发售金额-西安地铁售卖9号线发售的合计-西咸回收9号线   //sumD4_3
                     //西安地铁的回收合计*西安地铁与西安中铁的西安中铁铁运营商比例 
					 LOGGER.info("sumD9_16==="+sumD9_16_1+"dD1_7===="+dD1_7+"swCkClearOtherAccount.getStreamXaztXadtRecycle()===="+swCkClearOtherAccount.getStreamXaztXadtRecycle()+"sumD9_3===="+sumD9_3);
                     swCkClearOtherAccount.setStreamXaztXadtClear( (sumD9_16_1.multiply(new BigDecimal(String.valueOf(dD1_7)))).divide(decimal100).add(swCkClearOtherAccount.getStreamXaztXadtRecycle()).subtract(sumD9_3).setScale(scale5,BigDecimal.ROUND_HALF_UP));

					 //3.1.7 9号线大客流发售应急纸票且西咸回收（西安地铁-中铁-西咸三家清分）
                     swCkClearOtherAccount.setStreamXaztXixianRecycle(decimal);//TODO  待改
                     //西咸回收9号线金额合计*西安地铁、西咸、西安中铁三家的西安中铁运营商比例
                     String keyD5_7 = SwCkClearRuleConstans.CLEAR_RULE_EMERGENCY_BIGSTREAM+","+"5"+","+SwCkClearRuleConstans.SERVICE_ID_XAZT;                 
                     Double dD5_7 =  Double.valueOf(getData(mapLineClearRule.get(keyD5_7)));
                     swCkClearOtherAccount.setStreamXaztXixianClear((sumD5_3.multiply(new BigDecimal(String.valueOf(dD5_7))).divide(decimal100)).setScale(scale5,BigDecimal.ROUND_HALF_UP));
					
                 }
                 //TODO  根据日期范围+运营商ID+线路编号判断是否存在，如果存在更新，不存在插入
                 mapSaveData.put(lineCode, swCkClearOtherAccount);   
                 
             }// end for 循环线路
        	 //重新组织特殊情况退款 9,14号线机场段
			 /*
        	 SwCkClearEmergencyReturnticket account54 =  mapSaveData.get(SwCkClearRuleConstans.LINE_ID_AIR_14);
        	 SwCkClearEmergencyReturnticket account4 =  mapSaveData.get("4");
        	 SwCkClearEmergencyReturnticket account1 =  mapSaveData.get("1");
        	 SwCkClearEmergencyReturnticket account9 =  mapSaveData.get(SwCkClearRuleConstans.LINE_ID_XIXIAN_9); 
        	 
             account54.setFailSpeAirerrorClear(0-account4.getFailSpeAirerrorClear());          
             account54.setFailSpeXadterrorClear(0-account4.getFailSpeXadterrorClear());
             
             account9.setFailSpeXazterrorClear(0-account1.getFailSpeXazterrorClear()); 
             account9.setFailSpeXadterrorClear(0-account1.getFailSpeXadterrorClear());//TODO 规则 
             
             mapSaveData.put(SwCkClearRuleConstans.LINE_ID_AIR_14,account54);
             mapSaveData.put(SwCkClearRuleConstans.LINE_ID_XIXIAN_9,account9);
			 */

             //遍历map取对象
            for (SwCkClearEmergencyReturnticket value : mapSaveData.values()) {
                listAllSave.add(value);
            }
            if(listAllSave!=null && !listAllSave.isEmpty()){
                 return this.saveOrUpdateBatch(listAllSave);
            }

			//清分金额算出来后，存储到一个单程票月度表内，或者直接从这里查询，在视图中联合查询
        }//end if 线路是否为空
    	return false;
    }
    private BigDecimal getLongByLineCode(String lineCode,Map<String,String> map){
        if(map == null || map.isEmpty()){
            return new BigDecimal("0");
        }
        //map格式 key：'1', value：'12000'------key是lineCode值，value是金额
       if(map.containsKey(lineCode)){
           return new BigDecimal(map.get(lineCode));
       }
        return new BigDecimal("0");
    }
    
    private Long getSingleLong(Map<String,String> map){
        if(map == null || map.isEmpty()){
            return 0l;
        }
        return Long.parseLong(map.get("amount"));
    }
	private BigDecimal getLongByListMap(String lineCode,List<Map<String,String>> listMap){
        if(listMap == null || listMap.isEmpty()){
            return new BigDecimal("0");
        }
        for(Map<String,String> map : listMap){
            if(lineCode.equals(map.get("lineCode"))){
                return new BigDecimal(map.get("amount"));
            }
        }
        return new BigDecimal("0");
    }
    private String getData(String money){
        try {
            if(money == null){
                return "0";
            }
            return money;

        } catch (Exception e) {
            return "0";
        }

    }

    private BigDecimal getData2(BigDecimal money){
        try {
            if(money == null){
                return new  BigDecimal("0");
            }
            return money;

        } catch (Exception e) {
            return new  BigDecimal("0");
        }

    }

    /**
     * 导出数据
     * @param startDate  当月的开始日期
     * @param endDate    当月的结束日期
     * @param operators  运营商ID
     * @param lineCode   线路编号
     * @param response
     */
    @Override
    public void export(String startDate, String endDate, String operators, String lineCode, String baseCode, HttpServletResponse response){
        List<SwCkClearEmergencyReturnticketDTO> records = listSwCkClearEmergencyReturnticket(startDate,endDate,operators,lineCode);
        InputStream excelTemplateIs = null;
         try {
             response.reset(); // 非常重要
             response.setContentType("application/vnd.ms-excel");
             response.setCharacterEncoding("utf-8");
             WriteSheet writeSheet = null;
             if("0".equals(baseCode)){ // todo 0代表应急纸票和退票清分报表 1代表人工协议清分对账报表退换票 9代表人工协议清分对账报表（9号线） 54代表人工协议清分对账报表（14号线）
                 final String fileName = URLEncoder.encode("应急纸票和退票清分报表", "UTF-8");
                 response.setHeader("Content-disposition", "attachment;filename=" + fileName + System.currentTimeMillis() + ".xlsx");

                 // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
                 // {} 代表普通变量 {.} 代表是list的变量
                 //模版 TODO
                 excelTemplateIs = this.getClass().getResourceAsStream("/static/excel/template/export/SwCkClearEmergencyticketTemplate.xlsx");
                 writeSheet = EasyExcel.writerSheet("应急纸票和退票清分报表").build();

             }
             if("1".equals(baseCode)){
                 final String fileName = URLEncoder.encode("人工协议清分对账报表（退换票）", "UTF-8");
                 response.setHeader("Content-disposition", "attachment;filename=" + fileName + System.currentTimeMillis() + ".xlsx");

                 // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
                 // {} 代表普通变量 {.} 代表是list的变量
                 //模版 TODO
                 excelTemplateIs = this.getClass().getResourceAsStream("/static/excel/template/export/SwCkClearEmergencyReturnticketTemplate.xlsx");
                 writeSheet = EasyExcel.writerSheet("人工协议清分对账报表（退换票）").build();
             }
             if("9".equals(baseCode)){
                 final String fileName = URLEncoder.encode("人工协议清分对账报表（9号线）", "UTF-8");
                 response.setHeader("Content-disposition", "attachment;filename=" + fileName + System.currentTimeMillis() + ".xlsx");

                 // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
                 // {} 代表普通变量 {.} 代表是list的变量
                 //模版 TODO
                 excelTemplateIs = this.getClass().getResourceAsStream("/static/excel/template/export/9SwCkManmadeClearAccountOtherserviceReportExcelTemplate.xlsx");
                 writeSheet = EasyExcel.writerSheet("人工协议清分对账报表（9号线）").build();
             }
             if("54".equals(baseCode)){
                 final String fileName = URLEncoder.encode("人工协议清分对账报表（14号线机场段）", "UTF-8");
                 response.setHeader("Content-disposition", "attachment;filename=" + fileName + System.currentTimeMillis() + ".xlsx");

                 // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
                 // {} 代表普通变量 {.} 代表是list的变量
                 //模版 TODO
                 excelTemplateIs = this.getClass().getResourceAsStream("/static/excel/template/export/14SwCkManmadeClearAccountOtherserviceReportExcelTemplate.xlsx");
                 writeSheet = EasyExcel.writerSheet("人工协议清分对账报表（14号线机场段）").build();
             }
             // 这里注意 入参用了forceNewRow 代表在写入list的时候不管list下面有没有空行 都会创建一行，然后下面的数据往后移动。默认 是false，会直接使用下一行，如果没有则创建。
             // forceNewRow 如果设置了true,有个缺点 就是他会把所有的数据都放到内存了，所以慎用
             // 简单的说 如果你的模板有list,且list不是最后一行，下面还有数据需要填充 就必须设置 forceNewRow=true 但是这个就会把所有数据放到内存 会很耗内存
             // 如果数据量大 list不是最后一行 参照另一个
             ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerConverter(new LocalDateTimeConverter()).registerConverter(new LocalDateConverter()).withTemplate(excelTemplateIs).build();
             FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.FALSE).build();
             excelWriter.fill(records, fillConfig, writeSheet);
             Map<String, Object> map = new HashMap<>();
             map.put("beginTime", startDate);
             map.put("endTime", endDate);
             excelWriter.fill(map, writeSheet);
             excelWriter.finish();

         } catch (Exception e) {
             e.printStackTrace();
             LOGGER.error("导出失败");
         } finally {
             if(excelTemplateIs != null){
                 try {
                     excelTemplateIs.close();
                 } catch (IOException ioe) {
                     ioe.printStackTrace();
                 }
             }
         }     	
    }
    /**
     * 应急纸票和退换票正常清分操作（按月）
     * @return
     */
    @Override
    public Boolean reGenerateSwCkClearEmergencyReturnTicket(List<Long> ids){
    	return false;
    }

}
